Skip to content

Commit

Permalink
MDL-19967 No validation when adding a question with JS off.
Browse files Browse the repository at this point in the history
There was no check that a question type had been selected.
  • Loading branch information
timhunt committed May 6, 2010
1 parent 18db005 commit a27aa5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,5 @@
$string['upgradeproblemcouldnotupdatecategory'] = 'Could not update question category {$a->name} ({$a->id}).';
$string['upgradeproblemunknowncategory'] = 'Problem detected when upgrading question categories. Category {$a->id} refers to parent {$a->parent}, which does not exist. Parent changed to fix problem.';
$string['wrongprefix'] = 'Wrongly formatted nameprefix {$a}';
$string['youmustselectaqtype'] = 'You must select a question type.';
$string['yourfileshoulddownload'] = 'Your export file should start to download shortly. If not, please <a href="{$a}">click here</a>.';
2 changes: 2 additions & 0 deletions question/addquestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
$courseid = optional_param('courseid', 0, PARAM_INT);
$returnurl = optional_param('returnurl', 0, PARAM_LOCALURL);
$appendqnumstring = optional_param('appendqnumstring', '', PARAM_ALPHA);
$validationerror = optional_param('validationerror', false, PARAM_BOOL);

// Place to accumulate hidden params for the form we will print.
$hiddenparams = array('category' => $categoryid);
Expand Down Expand Up @@ -95,6 +96,7 @@
}

// Display a form to choose the question type.
echo $OUTPUT->notification(get_string('youmustselectaqtype', 'question'));
echo $OUTPUT->box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox');
print_choose_qtype_to_add_form($hiddenparams);
echo $OUTPUT->box_end();
Expand Down
9 changes: 9 additions & 0 deletions question/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
print_error('questiondoesnotexist', 'question', $returnurl);
}
get_question_options($question, true);

} else if ($categoryid && $qtype) { // only for creating new questions
$question = new stdClass;
$question->category = $categoryid;
Expand All @@ -100,6 +101,14 @@
if (!isset($allowedtypes[$qtype])) {
print_error('cannotenable', 'question', $returnurl, $qtype);
}

} else if ($categoryid) {
// Category, but no qtype. They probably came from the addquestion.php
// script without choosing a question type. Send them back.
$addurl = new moodle_url('/question/addquestion.php', $url->params());
$addurl->param('validationerror', 1);
redirect($addurl);

} else {
print_error('notenoughdatatoeditaquestion', 'question', $returnurl);
}
Expand Down

0 comments on commit a27aa5c

Please sign in to comment.