/**
  * The constructor function calls the abstract function definition() and it will then
  * process and clean and attempt to validate incoming data.
  *
  * It will call your custom validate method to validate data and will also check any rules
  * you have specified in definition using addRule
  *
  * The name of the form (id attribute of the form) is automatically generated depending on
  * the name you gave the class extending moodleform. You should call your class something
  * like
  *
  * @param mixed $action the action attribute for the form. If empty defaults to auto detect the
  *                  current url. If a moodle_url object then outputs params as hidden variables.
  * @param array $customdata if your form defintion method needs access to data such as $course
  *               $cm, etc. to construct the form definition then pass it in this array. You can
  *               use globals for somethings.
  * @param string $method if you set this to anything other than 'post' then _GET and _POST will
  *               be merged and used as incoming data to the form.
  * @param string $target target frame for form submission. You will rarely use this. Don't use
  *                  it if you don't need to as the target attribute is deprecated in xhtml
  *                  strict.
  * @param mixed $attributes you can pass a string of html attributes here or an array.
  * @return moodleform
  */
 function moodleform($action = null, $customdata = null, $method = 'post', $target = '', $attributes = null, $editable = true)
 {
     if (empty($action)) {
         $action = strip_querystring(qualified_me());
     }
     $this->_formname = get_class($this);
     // '_form' suffix kept in order to prevent collisions of form id and other element
     $this->_customdata = $customdata;
     $this->_form =& new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes);
     if (!$editable) {
         $this->_form->hardFreeze();
     }
     $this->set_upload_manager(new upload_manager());
     $this->definition();
     $this->_form->addElement('hidden', 'sesskey', null);
     // automatic sesskey protection
     $this->_form->setType('sesskey', PARAM_RAW);
     $this->_form->setDefault('sesskey', sesskey());
     $this->_form->addElement('hidden', '_qf__' . $this->_formname, null);
     // form submission marker
     $this->_form->setType('_qf__' . $this->_formname, PARAM_RAW);
     $this->_form->setDefault('_qf__' . $this->_formname, 1);
     $this->_form->_setDefaultRuleMessages();
     // we have to know all input types before processing submission ;-)
     $this->_process_submission($method);
 }