From 7e36bb719723f0df96472c46787719e184760470 Mon Sep 17 00:00:00 2001 From: Matt Porritt Date: Mon, 2 Feb 2015 13:21:46 +1100 Subject: [PATCH] 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). --- enrol/self/edit_form.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/enrol/self/edit_form.php b/enrol/self/edit_form.php index a1e3a8069b3..b035bd31252 100644 --- a/enrol/self/edit_form.php +++ b/enrol/self/edit_form.php @@ -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'));