From 41b2eb8400cf94954d7b8cefb786a1bf954c79c8 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Tue, 30 Apr 2013 17:39:56 +0100 Subject: [PATCH] MDL-39422 mod_forms: prevent long coruse module names To prevent ugly DB errors. --- mod/assign/mod_form.php | 1 + mod/assignment/mod_form.php | 1 + mod/book/mod_form.php | 1 + mod/chat/mod_form.php | 1 + mod/choice/mod_form.php | 1 + mod/data/mod_form.php | 1 + mod/feedback/mod_form.php | 1 + mod/folder/mod_form.php | 1 + mod/glossary/mod_form.php | 1 + mod/imscp/mod_form.php | 1 + mod/lesson/mod_form.php | 1 + mod/lti/mod_form.php | 1 + mod/page/mod_form.php | 1 + mod/quiz/mod_form.php | 1 + mod/resource/mod_form.php | 1 + mod/scorm/mod_form.php | 1 + mod/url/mod_form.php | 1 + mod/wiki/mod_form.php | 1 + 18 files changed, 18 insertions(+) diff --git a/mod/assign/mod_form.php b/mod/assign/mod_form.php index 45d6c6d8582..8bbc37ed0d4 100644 --- a/mod/assign/mod_form.php +++ b/mod/assign/mod_form.php @@ -57,6 +57,7 @@ class mod_assign_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('description', 'assign')); diff --git a/mod/assignment/mod_form.php b/mod/assignment/mod_form.php index 56b407d6ea6..bc0818fea2e 100644 --- a/mod/assignment/mod_form.php +++ b/mod/assignment/mod_form.php @@ -45,6 +45,7 @@ class mod_assignment_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('description', 'assignment')); diff --git a/mod/book/mod_form.php b/mod/book/mod_form.php index 8901645f5f1..6bf1dbc1373 100644 --- a/mod/book/mod_form.php +++ b/mod/book/mod_form.php @@ -45,6 +45,7 @@ class mod_book_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro, get_string('moduleintro')); $alloptions = book_get_numbering_types(); diff --git a/mod/chat/mod_form.php b/mod/chat/mod_form.php index 86025393207..294d2cdb0e4 100644 --- a/mod/chat/mod_form.php +++ b/mod/chat/mod_form.php @@ -22,6 +22,7 @@ class mod_chat_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('chatintro', 'chat')); diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index 70812f68b41..04011a0a46a 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -22,6 +22,7 @@ class mod_choice_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('chatintro', 'chat')); diff --git a/mod/data/mod_form.php b/mod/data/mod_form.php index c5f71206306..f8451d2932a 100644 --- a/mod/data/mod_form.php +++ b/mod/data/mod_form.php @@ -22,6 +22,7 @@ class mod_data_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('intro', 'data')); diff --git a/mod/feedback/mod_form.php b/mod/feedback/mod_form.php index 6256de76c10..9edb6cf75ec 100644 --- a/mod/feedback/mod_form.php +++ b/mod/feedback/mod_form.php @@ -44,6 +44,7 @@ class mod_feedback_mod_form extends moodleform_mod { $mform->addElement('text', 'name', get_string('name', 'feedback'), array('size'=>'64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true, get_string('description', 'feedback')); diff --git a/mod/folder/mod_form.php b/mod/folder/mod_form.php index 212cb125120..7500e2be07f 100644 --- a/mod/folder/mod_form.php +++ b/mod/folder/mod_form.php @@ -44,6 +44,7 @@ class mod_folder_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/glossary/mod_form.php b/mod/glossary/mod_form.php index 67456061340..ac0816f77d9 100644 --- a/mod/glossary/mod_form.php +++ b/mod/glossary/mod_form.php @@ -22,6 +22,7 @@ class mod_glossary_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor(true); diff --git a/mod/imscp/mod_form.php b/mod/imscp/mod_form.php index 34880b72dde..3514e3a1b04 100644 --- a/mod/imscp/mod_form.php +++ b/mod/imscp/mod_form.php @@ -45,6 +45,7 @@ class mod_imscp_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/lesson/mod_form.php b/mod/lesson/mod_form.php index 7f82372b8fd..dd99e80f6b5 100644 --- a/mod/lesson/mod_form.php +++ b/mod/lesson/mod_form.php @@ -89,6 +89,7 @@ class mod_lesson_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Create a text box that can be enabled/disabled for lesson time limit $timedgrp = array(); diff --git a/mod/lti/mod_form.php b/mod/lti/mod_form.php index 377c07da100..6e75dce2d19 100644 --- a/mod/lti/mod_form.php +++ b/mod/lti/mod_form.php @@ -67,6 +67,7 @@ class mod_lti_mod_form extends moodleform_mod { $mform->addElement('text', 'name', get_string('basicltiname', 'lti'), array('size'=>'64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Adding the optional "intro" and "introformat" pair of fields $this->add_intro_editor(false, get_string('basicltiintro', 'lti')); $mform->setAdvanced('introeditor'); diff --git a/mod/page/mod_form.php b/mod/page/mod_form.php index 9ec12872d87..b36c1f11d2d 100644 --- a/mod/page/mod_form.php +++ b/mod/page/mod_form.php @@ -47,6 +47,7 @@ class mod_page_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index 10e82f05a15..0e20651cef7 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -69,6 +69,7 @@ class mod_quiz_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Introduction. $this->add_intro_editor(false, get_string('introduction', 'quiz')); diff --git a/mod/resource/mod_form.php b/mod/resource/mod_form.php index 40be302c053..9813b8702d8 100644 --- a/mod/resource/mod_form.php +++ b/mod/resource/mod_form.php @@ -55,6 +55,7 @@ class mod_resource_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php index b9a79174ec2..10e28031b48 100644 --- a/mod/scorm/mod_form.php +++ b/mod/scorm/mod_form.php @@ -43,6 +43,7 @@ class mod_scorm_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Summary $this->add_intro_editor(true); diff --git a/mod/url/mod_form.php b/mod/url/mod_form.php index 47d42512bb9..bde836a7d19 100644 --- a/mod/url/mod_form.php +++ b/mod/url/mod_form.php @@ -45,6 +45,7 @@ class mod_url_mod_form extends moodleform_mod { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $this->add_intro_editor($config->requiremodintro); //------------------------------------------------------- diff --git a/mod/wiki/mod_form.php b/mod/wiki/mod_form.php index fd1196e7613..9c9cf0a885a 100644 --- a/mod/wiki/mod_form.php +++ b/mod/wiki/mod_form.php @@ -53,6 +53,7 @@ class mod_wiki_mod_form extends moodleform_mod { $mform->addElement('text', 'name', get_string('wikiname', 'wiki'), array('size' => '64')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', $required, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Adding the optional "intro" and "introformat" pair of fields $this->add_intro_editor(true, get_string('wikiintro', 'wiki'));