dirroot.'/lib/formslib.php'); class test_form extends moodleform { function definition() { $mform = $this->_form; $fieldname = 'firstformelement'; $elementgroup = array(); $elementgroup[] = $mform->createElement('checkbox', $fieldname.'_1', '', 'Spain'); $elementgroup[] = $mform->createElement('checkbox', $fieldname.'_2', '', 'France'); $elementgroup[] = $mform->createElement('checkbox', $fieldname.'_3', '', 'Germany'); $elementgroup[] = $mform->createElement('checkbox', $fieldname.'_4', '', 'Italy'); $mform->addGroup($elementgroup, $fieldname.'_group', 'Choose all the nations you like', '
', false); $fieldname = 'secondformelement'; $options = array('first option', 'second option', 'third option'); $mform->addElement('select', $fieldname, 'Just a drop down menu', $options); $test = 3; switch ($test) { case 1: $mform->disabledIf('secondformelement', 'firstformelement_1', 'eq', 0); $mform->disabledIf('secondformelement', 'firstformelement_2', 'eq', 1); $mform->disabledIf('secondformelement', 'firstformelement_3', 'eq', 1); $mform->disabledIf('secondformelement', 'firstformelement_4', 'eq', 0); break; case 2: $mform->disabledIf('secondformelement', 'firstformelement_1', 'eq', 0); $mform->disabledIf('secondformelement', 'firstformelement_2', 'checked'); $mform->disabledIf('secondformelement', 'firstformelement_3', 'checked'); $mform->disabledIf('secondformelement', 'firstformelement_4', 'eq', 0); break; case 3: $mform->disabledIf('secondformelement', 'firstformelement_1', 'notchecked'); $mform->disabledIf('secondformelement', 'firstformelement_2', 'eq', 1); $mform->disabledIf('secondformelement', 'firstformelement_3', 'eq', 1); $mform->disabledIf('secondformelement', 'firstformelement_4', 'notchecked'); break; case 4: $mform->disabledIf('secondformelement', 'firstformelement_1', 'notchecked'); $mform->disabledIf('secondformelement', 'firstformelement_2', 'checked'); $mform->disabledIf('secondformelement', 'firstformelement_3', 'checked'); $mform->disabledIf('secondformelement', 'firstformelement_4', 'notchecked'); break; default: } $this->add_action_buttons(); } } // =================== $PAGE->set_context(context_system::instance()); $PAGE->set_url('/mform_test.php'); $PAGE->set_title('mform_test'); $mform = new test_form(new moodle_url('/mform_test.php')); if ($mform->is_cancelled()) { } if ($data = $mform->get_data()) { } echo $OUTPUT->header(); $mform->display(); echo $OUTPUT->footer();