MDL-56912 feedback: empty multichoice questions do not submit

This commit is contained in:
Marina Glancy
2016-12-13 15:01:11 +08:00
parent 45fe30fc2d
commit e02a11ad0a
3 changed files with 11 additions and 0 deletions
@@ -181,6 +181,7 @@ abstract class feedback_item_base {
* If it is important which mode the form is in, use $form->get_mode()
*
* Each item type must add a single form element with the name $item->typ.'_'.$item->id
* This element must always be present in form data even if nothing is selected (i.e. use advcheckbox and not checkbox).
* To add an element use either:
* $form->add_form_element() - adds a single element to the form
* $form->add_form_group_element() - adds a group element to the form
+5
View File
@@ -349,11 +349,16 @@ class feedback_item_multichoice extends feedback_item_base {
}
} else {
// Radio.
if (!array_key_exists(0, $options)) {
// Always add '0' as hidden element, otherwise form submit data may not have this element.
$objs[] = ['hidden', $inputname.'[0]'];
}
foreach ($options as $idx => $label) {
$objs[] = ['radio', $inputname.'[0]', '', $label, $idx];
}
$element = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class);
$form->set_element_default($inputname.'[0]', $tmpvalue);
$form->set_element_type($inputname.'[0]', PARAM_INT);
}
}
@@ -302,12 +302,17 @@ class feedback_item_multichoicerated extends feedback_item_base {
['select', $inputname, $name, array('' => '') + $options, array('class' => $class)]);
} else {
$objs = array();
if (!array_key_exists(0, $options)) {
// Always add '0' as hidden element, otherwise form submit data may not have this element.
$objs[] = ['hidden', $inputname];
}
foreach ($options as $idx => $label) {
$objs[] = ['radio', $inputname, '', $label, $idx];
}
$separator = $info->horizontal ? ' ' : '<br>';
$class .= ' multichoicerated-' . ($info->horizontal ? 'horizontal' : 'vertical');
$el = $form->add_form_group_element($item, 'group_'.$inputname, $name, $objs, $separator, $class);
$form->set_element_type($inputname, PARAM_INT);
// Set previously input values.
$form->set_element_default($inputname, $form->get_item_value($item));