phpformsmoodleform-api

Moodle form: A required parameter is missing


I added a drop down list in the Question Editing form by the following code in the definition() function of edit_question_form.php:

$mform -> addElement('select', 'qtype', 'Choose type', array('optionOne' => 'Value Option One', 'optionTwo' => 'Value Option Two', 'optionThree' => 'valueOptionThree'), array('id'=>'id_dropdown'));

$mform->addRule('qtype', get_string('error'), 'required', 'server'(default), false, false);

And the action of this form points to question.php, so in question.php, I added the following statement:

$qtypeq = required_param('qtype', PARAM_TEXT);

But I get the following error:

A required parameter (qtype) was missing

Aparently it is not missing.

So can anybody suggest why am I getting this error and what can I do to fix it?


Solution

  • The first step I'd take would be to open up the developer tools in my browser, switch to the 'network' tab, then check exactly what params are sent when the form is submitted.

    If the 'qtype' param is definitely there at that point, then the next step would be to add a 'var_dump($_REQUEST);' immediately before the 'required_param' line (this will output every param that has been sent to the page via get or post).

    If that doesn't shed any light on what is happening, then the next thing to do would be to install xdebug and configure your IDE to work with it. You can then stick a breakpoint on the 'required_param' line and step through it and see exactly what is going wrong (as an aside, even if you don't need it this time, install xdebug anyway, as it will help a lot in the future).