MDL-49034 enrol_self: Enforce maxlength in self enrolment form fields.
Alter self enrolment creation form to enforce max field lengths. Limit "Custom instance name" (name) form field to 255 characters via maxlength. Limit "Enrolment key" (password) form field to 50 characters via maxlength. Fix for when the form is submitted causing a database write error to be thrown as corresponding field "name" in the table mdl_enrol is set to varchar(255) and database field "password" is varying(50).
This commit is contained in:
@@ -39,8 +39,10 @@ class enrol_self_edit_form extends moodleform {
|
||||
|
||||
$mform->addElement('header', 'header', get_string('pluginname', 'enrol_self'));
|
||||
|
||||
$mform->addElement('text', 'name', get_string('custominstancename', 'enrol'));
|
||||
$nameattribs = array('size' => '20', 'maxlength' => '255');
|
||||
$mform->addElement('text', 'name', get_string('custominstancename', 'enrol'), $nameattribs);
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'server');
|
||||
|
||||
$options = array(ENROL_INSTANCE_ENABLED => get_string('yes'),
|
||||
ENROL_INSTANCE_DISABLED => get_string('no'));
|
||||
@@ -52,11 +54,13 @@ class enrol_self_edit_form extends moodleform {
|
||||
$mform->addHelpButton('customint6', 'newenrols', 'enrol_self');
|
||||
$mform->disabledIf('customint6', 'status', 'eq', ENROL_INSTANCE_DISABLED);
|
||||
|
||||
$mform->addElement('passwordunmask', 'password', get_string('password', 'enrol_self'));
|
||||
$passattribs = array('size' => '20', 'maxlength' => '50');
|
||||
$mform->addElement('passwordunmask', 'password', get_string('password', 'enrol_self'), $passattribs);
|
||||
$mform->addHelpButton('password', 'password', 'enrol_self');
|
||||
if (empty($instance->id) and $plugin->get_config('requirepassword')) {
|
||||
$mform->addRule('password', get_string('required'), 'required', null, 'client');
|
||||
}
|
||||
$mform->addRule('password', get_string('maximumchars', '', 50), 'maxlength', 50, 'server');
|
||||
|
||||
$options = array(1 => get_string('yes'),
|
||||
0 => get_string('no'));
|
||||
|
||||
Reference in New Issue
Block a user