#71 Added validation for element and template name length
This commit is contained in:
parent
055a82e69b
commit
9a8bf74714
3 changed files with 16 additions and 3 deletions
|
@ -49,7 +49,7 @@ class edit_element_form extends \moodleform {
|
|||
$element = $this->_customdata['element'];
|
||||
|
||||
// Add the field for the name of the element, this is required for all elements.
|
||||
$mform->addElement('text', 'name', get_string('elementname', 'customcert'));
|
||||
$mform->addElement('text', 'name', get_string('elementname', 'customcert'), 'maxlength="255"');
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->setDefault('name', get_string('pluginname', 'customcertelement_' . $element->element));
|
||||
$mform->addRule('name', get_string('required'), 'required', null, 'client');
|
||||
|
@ -76,6 +76,14 @@ class edit_element_form extends \moodleform {
|
|||
* @return array the errors that were found
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
return $this->element->validate_form_elements($data, $files);
|
||||
$errors = array();
|
||||
|
||||
if (\core_text::strlen($data['name']) > 255) {
|
||||
$errors['name'] = get_string('nametoolong', 'customcert');
|
||||
}
|
||||
|
||||
$errors += $this->element->validate_form_elements($data, $files);
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class edit_form extends \moodleform {
|
|||
|
||||
$mform =& $this->_form;
|
||||
|
||||
$mform->addElement('text', 'name', get_string('name', 'customcert'));
|
||||
$mform->addElement('text', 'name', get_string('name', 'customcert'), 'maxlength="255"');
|
||||
$mform->setType('name', PARAM_TEXT);
|
||||
$mform->addRule('name', null, 'required');
|
||||
|
||||
|
@ -130,6 +130,10 @@ class edit_form extends \moodleform {
|
|||
public function validation($data, $files) {
|
||||
$errors = parent::validation($data, $files);
|
||||
|
||||
if (\core_text::strlen($data['name']) > 255) {
|
||||
$errors['name'] = get_string('nametoolong', 'customcert');
|
||||
}
|
||||
|
||||
// Go through the data and check any width, height or margin values.
|
||||
foreach ($data as $key => $value) {
|
||||
if (strpos($key, 'pagewidth_') !== false) {
|
||||
|
|
|
@ -86,6 +86,7 @@ $string['modulename_help'] = 'This module allows for the dynamic generation of P
|
|||
$string['modulename_link'] = 'Custom_certificate_module';
|
||||
$string['mycertificates'] = 'My certificates';
|
||||
$string['name'] = 'Name';
|
||||
$string['nametoolong'] = 'You have exceeded the maximum length allowed for the name';
|
||||
$string['nocustomcerts'] = 'There are no custom certificates for this course';
|
||||
$string['noimage'] = 'No image';
|
||||
$string['notemplates'] = 'No templates';
|
||||
|
|
Loading…
Reference in a new issue