title: Error: A required parameter (id) was missing when redirect URL in form Moodle
body: <p>Moodle 3, developing a block</p>
  
  <p>I'm getting the following  error: 'A required parameter (id) was missing'. </p>
  
  <p>It happens in $mform, only when I'm using the array('id' => $instance->id) in the 'Else if' statement in the redirect($url). </p>
  
  <p>Surprisingly, because when I'm using the same code in a button with a redirect url, the code works correct.</p>
  
  <p>I've tried several things, but nothing helps. What could be the problem?</p>
  
  <p>Here is some code:</p>
  
  <pre><code>$id = required_param('id', PARAM_INT);
  
  $instance = $DB-&gt;get_record('block_instances', array('id' =&gt; $id), '*', MUST_EXIST);
  
  $context       = \context_block::instance($instance-&gt;id);
  
  $mform = new newlink();
  
  if ($mform-&gt;is_cancelled()) {
  
       $url = new moodle_url('/my');
  
       redirect($url);
  
  } else if ($fromform = $mform-&gt;get_data()) {
  
  // data from form
  
  ....
  
  $url = new moodle_url('/blocks/name_of_block/links.php', array('id' =&gt;  $instance-&gt;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-&gt;set_data($toform);
  
  //displays the form
  
  $mform-&gt;display();
  
  }
  
  $url = new moodle_url('/blocks/name_of_block/links.php', array('id' =&gt; $instance-&gt;id))
  
  echo $OUTPUT-&gt;single_button($url, get_string('button:links', 'block_name_of_block')); // THIS IS WORKING CORRECT
  </code></pre>