From 00456f0bed788a69829568a411cce644871acaf1 Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Tue, 19 Apr 2016 15:39:31 +0800 Subject: [PATCH] MDL-53865 tool_lp: Add maxlength attr and validation for input fields --- admin/tool/lp/classes/form/competency.php | 11 +++++++---- admin/tool/lp/classes/form/competency_framework.php | 11 +++++++---- admin/tool/lp/classes/form/plan.php | 5 ++++- admin/tool/lp/classes/form/template.php | 6 ++++-- admin/tool/lp/classes/form/user_evidence.php | 4 +++- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/admin/tool/lp/classes/form/competency.php b/admin/tool/lp/classes/form/competency.php index 7073f22ff7c..e9b50508504 100644 --- a/admin/tool/lp/classes/form/competency.php +++ b/admin/tool/lp/classes/form/competency.php @@ -92,17 +92,20 @@ class competency extends persistent { $pagecontextid)); } - $mform->addElement('text', 'shortname', - get_string('shortname', 'tool_lp')); + // Name. + $mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"'); $mform->setType('shortname', PARAM_TEXT); $mform->addRule('shortname', null, 'required', null, 'client'); + $mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); + // Description. $mform->addElement('editor', 'description', get_string('description', 'tool_lp'), array('rows' => 4)); $mform->setType('description', PARAM_RAW); - $mform->addElement('text', 'idnumber', - get_string('idnumber', 'tool_lp')); + // ID number. + $mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"'); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', null, 'required', null, 'client'); + $mform->addRule('idnumber', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); $scales = array(null => get_string('inheritfromframework', 'tool_lp')) + get_scales_menu(); $scaleid = $mform->addElement('select', 'scaleid', get_string('scale', 'tool_lp'), $scales); diff --git a/admin/tool/lp/classes/form/competency_framework.php b/admin/tool/lp/classes/form/competency_framework.php index c60ecdd774e..974c2ba6b99 100644 --- a/admin/tool/lp/classes/form/competency_framework.php +++ b/admin/tool/lp/classes/form/competency_framework.php @@ -54,17 +54,20 @@ class competency_framework extends persistent { $mform->addElement('header', 'generalhdr', get_string('general')); - $mform->addElement('text', 'shortname', - get_string('shortname', 'tool_lp')); + // Name. + $mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"'); $mform->setType('shortname', PARAM_TEXT); $mform->addRule('shortname', null, 'required', null, 'client'); + $mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); + // Description. $mform->addElement('editor', 'description', get_string('description', 'tool_lp'), array('rows' => 4)); $mform->setType('description', PARAM_RAW); - $mform->addElement('text', 'idnumber', - get_string('idnumber', 'tool_lp')); + // ID number. + $mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"'); $mform->setType('idnumber', PARAM_TEXT); $mform->addRule('idnumber', null, 'required', null, 'client'); + $mform->addRule('idnumber', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); $scales = get_scales_menu(); $scaleid = $mform->addElement('select', 'scaleid', get_string('scale', 'tool_lp'), $scales); diff --git a/admin/tool/lp/classes/form/plan.php b/admin/tool/lp/classes/form/plan.php index 54604ee93e0..461f8c2e887 100644 --- a/admin/tool/lp/classes/form/plan.php +++ b/admin/tool/lp/classes/form/plan.php @@ -52,9 +52,12 @@ class plan extends persistent { $mform->addElement('header', 'generalhdr', get_string('general')); - $mform->addElement('text', 'name', get_string('planname', 'tool_lp')); + // Name. + $mform->addElement('text', 'name', get_string('planname', 'tool_lp'), 'maxlength="100"'); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); + // Description. $mform->addElement('editor', 'description', get_string('plandescription', 'tool_lp'), array('rows' => 4)); $mform->setType('description', PARAM_RAW); diff --git a/admin/tool/lp/classes/form/template.php b/admin/tool/lp/classes/form/template.php index e5f69408c2f..8922d249bec 100644 --- a/admin/tool/lp/classes/form/template.php +++ b/admin/tool/lp/classes/form/template.php @@ -50,10 +50,12 @@ class template extends persistent { $mform->addElement('header', 'generalhdr', get_string('general')); - $mform->addElement('text', 'shortname', - get_string('shortname', 'tool_lp')); + // Name. + $mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"'); $mform->setType('shortname', PARAM_TEXT); $mform->addRule('shortname', null, 'required', null, 'client'); + $mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); + // Description. $mform->addElement('editor', 'description', get_string('description', 'tool_lp'), array('rows' => 4)); $mform->setType('description', PARAM_RAW); diff --git a/admin/tool/lp/classes/form/user_evidence.php b/admin/tool/lp/classes/form/user_evidence.php index 7741444a45c..8faac4d57ad 100644 --- a/admin/tool/lp/classes/form/user_evidence.php +++ b/admin/tool/lp/classes/form/user_evidence.php @@ -47,10 +47,12 @@ class user_evidence extends persistent { $mform->addElement('header', 'generalhdr', get_string('general')); + // Name. $mform->addElement('text', 'name', get_string('userevidencename', 'tool_lp'), 'maxlength="100"'); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); - + $mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); + // Description. $mform->addElement('editor', 'description', get_string('userevidencedescription', 'tool_lp'), array('rows' => 10)); $mform->setType('description', PARAM_RAW);