title: Inserting data into the database when 'submit' button pressed in moodle forms
body: <p>I'm using Moodle installation v 2.3.4, and have created a simple form in the NEWMODULE plugin and using it to enter 2 fields, name and description.</p>
  
  <p>I want to insert the data entered in the database, but the data is not getting inserted.
  After pressing Submit, moodle looks for modedit.php, which is ofcourse not in the present directory, thus 'page not found' error is displayed.</p>
  
  <p>The code snippets are shown:
  make_form.php (The forms page):</p>
  
  <pre><code>&lt;?php
  require_once('../../config.php');
  require_once('mod_form.php');
  require_login($course, true);
  
  echo $OUTPUT-&gt;header();
  $mform = new mod_testform_mod_form();
  
  if ($mform-&gt;is_cancelled()) {
  
  }
  else if ($fromform = $mform-&gt;get_data()) {
  
  //      print_object($fromform);    
      $record = new stdClass();       
      $record-&gt;id='';
      $record-&gt;name= $fromform-&gt;name;
      $record-&gt;description= $fromform-&gt;desc;
      $DB=insert_record('testform_details', $record, false);
      $mform-&gt;display();
  }
  else {
      $mform-&gt;set_data($toform);
      $mform-&gt;display();
      print_footer($course);
  }
  ?&gt;
  </code></pre>
  
  <p>mod_form.php </p>
  
  <pre><code>&lt;?php
  
  defined('MOODLE_INTERNAL') || die();
  require_once($CFG-&gt;dirroot.'/course/moodleform_mod.php');
  
  class mod_testform_mod_form extends moodleform_mod {
  
  public function definition() {
  
      $mform = $this-&gt;_form;
  
      $mform-&gt;addElement('header', 'general', get_string('general', 'testform'));
      $mform-&gt;addElement('text', 'name', get_string('name', 'testform'));
      if (!empty($CFG-&gt;formatstringstriptags)) {
          $mform-&gt;setType('name', PARAM_TEXT);
      } else {
          $mform-&gt;setType('name', PARAM_CLEAN);
      }
      $mform-&gt;addRule('name', null, 'required', null, 'client');
      $mform-&gt;addHelpButton('name', 'name', 'testform');
  
  //      $this-&gt;add_intro_editor();
      $mform-&gt;addElement('editor', 'desc', get_string('description','testform'));
      $mform-&gt;setType('desc', PARAM_RAW);
      $mform-&gt;addHelpButton('desc', 'description', 'testform');
  
      $buttonarray=array();
      $buttonarray[] = &amp;$mform-&gt;createElement('submit', 'submitbutton', get_string('savechanges'));
      $buttonarray[] = &amp;$mform-&gt;createElement('reset', 'resetbutton', get_string('reset'));
      $buttonarray[] = &amp;$mform-&gt;createElement('cancel');
      $mform-&gt;addGroup($buttonarray, 'buttonar', '', array(' '), false);
      $mform-&gt;closeHeaderBefore('buttonar');
  }
  }
  </code></pre>