Skip to content

Commit

Permalink
MDL-48215 gradingform_guide: Name length validation
Browse files Browse the repository at this point in the history
Validating both criterion name and guide name to be 255 chars.
  • Loading branch information
mhughes2k authored and mdjnelson committed Feb 16, 2015
1 parent 201f508 commit 5b7e736
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion grade/grading/form/guide/edit_form.php
Expand Up @@ -51,9 +51,11 @@ public function definition() {
$form->setType('returnurl', PARAM_LOCALURL);

// Name.
$form->addElement('text', 'name', get_string('name', 'gradingform_guide'), array('size'=>52));
$form->addElement('text', 'name', get_string('name', 'gradingform_guide'),
array('size' => 52, 'maxlength' => 255));
$form->addRule('name', get_string('required'), 'required');
$form->setType('name', PARAM_TEXT);
$form->addRule('name', null, 'maxlength', 255, 'client');

// Description.
$options = gradingform_guide_controller::description_form_field_options($this->_customdata['context']);
Expand Down
4 changes: 4 additions & 0 deletions grade/grading/form/guide/guideeditor.php
Expand Up @@ -197,6 +197,10 @@ protected function prepare_data($value = null, $withvalidation = false) {
$errors['err_noshortname'] = 1;
$criterion['error_description'] = true;
}
if (strlen(trim($criterion['shortname'])) > 255) {
$errors['err_shortnametoolong'] = 1;
$criterion['error_description'] = true;
}
if (!strlen(trim($criterion['maxscore']))) {
$errors['err_nomaxscore'] = 1;
$criterion['error_description'] = true;
Expand Down
1 change: 1 addition & 0 deletions grade/grading/form/guide/lang/en/gradingform_guide.php
Expand Up @@ -54,6 +54,7 @@
$string['err_nodescriptionmarkers'] = 'Marker description can not be empty';
$string['err_nomaxscore'] = 'Criterion max score can not be empty';
$string['err_noshortname'] = 'Criterion name can not be empty';
$string['err_shortnametoolong'] = 'Criterion name must be less than 256 characters';
$string['err_scoreinvalid'] = 'The score given to {$a->criterianame} is not valid, the max score is: {$a->maxscore}';
$string['gradingof'] = '{$a} grading';
$string['guidemappingexplained'] = 'WARNING: Your marking guide has a maximum grade of <b>{$a->maxscore} points</b> but the maximum grade set in your activity is {$a->modulegrade} The maximum score set in your marking guide will be scaled to the maximum grade in the module.<br />
Expand Down

0 comments on commit 5b7e736

Please sign in to comment.