MDL-52831 users: Automatically strip whitespace from name fields

This change prevents from registering and/or saving the profile of a
user with the whitespace instead of the required name.

Additionally, there is accessibility improvement for better error labels
in case of missing values (copied over from signup_form).
This commit is contained in:
David Mudrák
2016-01-19 21:32:42 +01:00
parent 6a01418aa1
commit 73f2ca5411
5 changed files with 73 additions and 1 deletions
+7 -1
View File
@@ -285,11 +285,17 @@ function useredit_shared_definition(&$mform, $editoroptions, $filemanageroptions
}
$strrequired = get_string('required');
$stringman = get_string_manager();
// Add the necessary names.
foreach (useredit_get_required_name_fields() as $fullname) {
$mform->addElement('text', $fullname, get_string($fullname), 'maxlength="100" size="30"');
$mform->addRule($fullname, $strrequired, 'required', null, 'client');
if ($stringman->string_exists('missing'.$fullname, 'core')) {
$strmissingfield = get_string('missing'.$fullname, 'core');
} else {
$strmissingfield = $strrequired;
}
$mform->addRule($fullname, $strmissingfield, 'required', null, 'client');
$mform->setType($fullname, PARAM_NOTAGS);
}