Error: A required parameter (id) was missing when redirect URL in form Moodle

Error: A required parameter (id) was missing when redirect URL in form Moodle

by Franky Just -
Number of replies: 1

Moodle 3.0 - Block development

I'm getting an error: 'A required parameter (id) was missing', in $mform, only when I'm using in the Else if statement in the redirect($url), the array('id' => $instance->id). 

Surprisingly, because when I'm using the same code in a button, it works correct.

I've tried several things, but nothing helps. What could be the problem?

Here is some code:


$id = required_param('id', PARAM_INT);

$instance = $DB->get_record('block_instances', array('id' => $id), '*', MUST_EXIST);

$context       = \context_block::instance($instance->id);


$mform = new newlink();

if ($mform->is_cancelled()) {

    $url = new moodle_url('/my');

    redirect($url);

} else if ($fromform = $mform->get_data()) {

 // data from form

....

$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id)); // HERE IS THE PROBLEM

(Note: when I'm using here the block instance id number 123 directly, the redirect is working correct:

$url = new moodle_url('/blocks/name_of_block/links.php?id=123';)

redirect ($url);

} else {

     //Set default data (if any)

    $mform->set_data($toform);

    //displays the form

    $mform->display();

}

$url = new moodle_url('/blocks/name_of_block/links.php', array('id' => $instance->id))

echo $OUTPUT->single_button($url, get_string('button:links', 'block_name_of_block')); // THIS IS WORKING CORRECT

Average of ratings: -
In reply to Franky Just

Re: Error: A required parameter (id) was missing when redirect URL in form Moodle

by Franky Just -
problem solved by changing form definition