diff --git a/lib/formslib.php b/lib/formslib.php index d4563aa3e91..eeb54e40096 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -74,11 +74,8 @@ class moodleform { * @var upload_manager */ var $_upload_manager; // - /** - * definition_after_data executed flag - * @var definition_finalized - */ - var $_definition_finalized = false; + + /** * The constructor function calls the abstract function definition() and it will then @@ -91,8 +88,8 @@ class moodleform { * 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 string $action the action attribute for the form. If empty defaults to auto detect the + * current url. * @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. @@ -104,7 +101,7 @@ class moodleform { * @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) { + function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null) { if (empty($action)){ $action = strip_querystring(qualified_me()); } @@ -112,9 +109,6 @@ class moodleform { $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(); @@ -127,6 +121,9 @@ class moodleform { // we have to know all input types before processing submission ;-) $this->_process_submission($method); + + // update form definition based on final data + $this->definition_after_data(); } /** @@ -242,6 +239,8 @@ class moodleform { } $filter = $slashed ? 'stripslashes' : NULL; $this->_form->setDefaults($default_values, $filter); + //update form definition when data changed + $this->definition_after_data(); } /** @@ -297,12 +296,6 @@ class moodleform { static $validated = null; // one validation is enough $mform =& $this->_form; - //finalize the form definition before any processing - if (!$this->_definition_finalized) { - $this->_definition_finalized = true; - $this->definition_after_data(); - } - if ($this->no_submit_button_pressed()){ return false; } elseif ($validated === null) { @@ -373,29 +366,6 @@ class moodleform { } } - /** - * Return submitted data without validation or NULL if there is no submitted data. - * - * @param bool $slashed true means return data with addslashes applied - * @return object submitted data; NULL if not submitted - */ - function get_submitted_data($slashed=true) { - $mform =& $this->_form; - - if ($this->is_submitted()) { - $data = $mform->exportValues(null, $slashed); - unset($data['sesskey']); // we do not need to return sesskey - unset($data['_qf__'.$this->_formname]); // we do not need the submission marker too - if (empty($data)) { - return NULL; - } else { - return (object)$data; - } - } else { - return NULL; - } - } - /** * Save verified uploaded files into directory. Upload process can be customised from definition() * method by creating instance of upload manager and storing it in $this->_upload_form @@ -423,11 +393,6 @@ class moodleform { * Print html form. */ function display() { - //finalize the form definition if not yet done - if (!$this->_definition_finalized) { - $this->_definition_finalized = true; - $this->definition_after_data(); - } $this->_form->display(); } @@ -457,9 +422,13 @@ class moodleform { * @return bool array of errors or true if ok */ function validation($data) { - return array(); + return true; } + + + + /** * Method to add a repeating group of elements to a form. * @@ -576,11 +545,11 @@ class moodleform { $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel); $buttonarray[] = &$mform->createElement('cancel'); $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); - $mform->closeHeaderBefore('buttonar'); + $mform->closeHeaderBefore('buttonar'); } else { //no group needed $mform->addElement('submit', 'submitbutton', $submitlabel); - $mform->closeHeaderBefore('submitbutton'); + $mform->closeHeaderBefore('submitbutton'); } } } @@ -631,18 +600,11 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless { */ var $_formName = ''; - /** - * String with the html for hidden params passed in as part of a moodle_url object for the action. Output in the form. - * - * @var string - */ - var $_pageparams = ''; - /** * Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless * @param string $formName Form's name. * @param string $method (optional)Form's method defaults to 'POST' - * @param mixed $action (optional)Form's action - string or moodle_url + * @param string $action (optional)Form's action * @param string $target (optional)Form's target defaults to none * @param mixed $attributes (optional)Extra attributes for