title: Cancel button submitting the form data in Moodle
body: <p>Initially I don't use the <code>cancel</code> button in my <code>moodle form</code>. My form looks like:</p>
  
  <pre><code>require_once("{$CFG-&gt;libdir}/formslib.php");
  
  class quest_form extends moodleform {
  
      function definition() {
          global $DB;
          $mform =&amp;$this-&gt;_form;
  
          $mform-&gt;addElement('header','displayinfo', 'Add Question');
  
          // add question.
          $mform-&gt;addElement('editor', 'title', 'Question');
          $mform-&gt;addRule('title', null, 'required', null, 'client');
          $mform-&gt;setType('title', PARAM_RAW);
          // add answer.
          $mform-&gt;addElement('editor', 'answer', 'Answer');
          $mform-&gt;addRule('answer', null, 'required', null, 'client');
          $mform-&gt;setType('answer', PARAM_RAW);
  
          $mform-&gt;addElement('hidden', 'blockid');
          $mform-&gt;setType('blockid', PARAM_RAW);
          $mform-&gt;addElement('hidden', 'courseid');
          $mform-&gt;setType('courseid', PARAM_RAW);
          $this-&gt;add_action_buttons(false, 'submit');
      }
  </code></pre>
  
  <p>Now I want to use <code>cancel</code> button in my form so I replace the line</p>
  
  <pre><code>$this-&gt;add_action_buttons(false, 'submit');
  </code></pre>
  
  <p>with</p>
  
  <pre><code>$this-&gt;add_action_buttons(true, 'submit');
  </code></pre>
  
  <p>The <code>cancel</code> button is displayed successfully but while clicking the <code>cancel</code> button <code>the form gets submitted</code>(even if there is no data in form fields).</p>
  
  <p>How can I resolve this? Am I miss anything else??</p>
  
  <p>Please help me...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Depending upon <em>Russell England</em> answer. I try like below:</p>
  
  <pre><code>    $qform = new quest_form ();
      if ($qform -&gt;is_cancelled()){
        redirect("view.php?id={$cid}");
      }else{
        $qform = new pool_form("pool_action.php?id={$cid}&amp;qpid={$questplace-&gt;id}&amp;qtype={$qtype}");
      }   
      $qform -&gt;display();
  </code></pre>
  
  <p>But still the <code>cancel button</code> submit the form.</p>