From 7f40a229a4c65f0111686885e3d22e70244eff07 Mon Sep 17 00:00:00 2001 From: skodak Date: Thu, 12 Oct 2006 07:33:57 +0000 Subject: [PATCH] New version of formslib.php (see MDL-6914 for more details), course/edit2.php is disabled for now - working on edit3.php ;-) More inline comments/docs today. --- course/edit2.php | 4 + lib/form/checkbox.php | 2 +- lib/form/dateselector.php | 10 +- lib/form/datetimeselector.php | 14 +- lib/form/file.php | 2 +- lib/form/group.php | 2 +- lib/form/hidden.php | 2 +- lib/form/htmleditor.php | 6 +- lib/form/password.php | 2 +- lib/form/radio.php | 2 +- lib/form/select.php | 2 +- lib/form/static.php | 2 +- lib/form/text.php | 2 +- lib/form/textarea.php | 2 +- lib/formslib.php | 394 +++++++++++++++++----------------- 15 files changed, 222 insertions(+), 226 deletions(-) diff --git a/course/edit2.php b/course/edit2.php index f4b57fc494..0ece023719 100644 --- a/course/edit2.php +++ b/course/edit2.php @@ -8,6 +8,10 @@ include_once $CFG->libdir.'/formslib.php'; + print_header(); + notice('This file is disabled due to recent changes in formslib.php, edit3.php will be here soon ;-).'); + die; + require_login(); $mform =& new moodleform('edit_course', 'post', 'edit2.php'); diff --git a/lib/form/checkbox.php b/lib/form/checkbox.php index 0817ca9b26..69ff6fe2b8 100644 --- a/lib/form/checkbox.php +++ b/lib/form/checkbox.php @@ -7,7 +7,7 @@ require_once('HTML/QuickForm/checkbox.php'); * @author Jamie Pratt * @access public */ -class moodleform_checkbox extends HTML_QuickForm_checkbox{ +class MoodleQuickForm_checkbox extends HTML_QuickForm_checkbox{ /** * html for help button, if empty then no help * diff --git a/lib/form/dateselector.php b/lib/form/dateselector.php index 9ce344fb5c..8857fa2a1c 100644 --- a/lib/form/dateselector.php +++ b/lib/form/dateselector.php @@ -11,7 +11,7 @@ require_once "$CFG->libdir/formslib.php"; * @author Jamie Pratt * @access public */ -class moodleform_date_selector extends moodleform_group +class MoodleQuickForm_date_selector extends MoodleQuickForm_group { /** * Control the fieldnames for form elements @@ -40,7 +40,7 @@ class moodleform_date_selector extends moodleform_group * @param array Options to control the element's display * @param mixed Either a typical HTML attribute string or an associative array */ - function moodleform_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) + function MoodleQuickForm_date_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; @@ -75,9 +75,9 @@ class moodleform_date_selector extends moodleform_group for ($i=$this->_options['startyear']; $i<=$this->_options['stopyear']; $i++) { $years[$i] = $i; } - $this->_elements[] =& moodleform::createElement('select', 'day', null, $days, $this->getAttributes(), true); - $this->_elements[] =& moodleform::createElement('select','month', null, $months, $this->getAttributes(), true); - $this->_elements[] =& moodleform::createElement('select','year', null, $years, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select', 'day', null, $days, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select','month', null, $months, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select','year', null, $years, $this->getAttributes(), true); } diff --git a/lib/form/datetimeselector.php b/lib/form/datetimeselector.php index 04f6850603..4d4d78c1fb 100644 --- a/lib/form/datetimeselector.php +++ b/lib/form/datetimeselector.php @@ -11,7 +11,7 @@ require_once "$CFG->libdir/formslib.php"; * @author Jamie Pratt * @access public */ -class moodleform_date_time_selector extends moodleform_group{ +class MoodleQuickForm_date_time_selector extends MoodleQuickForm_group{ /** * Options for the element * @@ -42,7 +42,7 @@ class moodleform_date_time_selector extends moodleform_group{ * @param array Options to control the element's display * @param mixed Either a typical HTML attribute string or an associative array */ - function moodleform_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) + function MoodleQuickForm_date_time_selector($elementName = null, $elementLabel = null, $options = array(), $attributes = null) { $this->HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; @@ -83,11 +83,11 @@ class moodleform_date_time_selector extends moodleform_group{ for ($i=0; $i<60; $i+=$this->_options['step']) { $minutes[$i] = sprintf("%02d",$i); } - $this->_elements[] =& moodleform::createElement('select', 'day', null, $days, $this->getAttributes(), true); - $this->_elements[] =& moodleform::createElement('select','month', null, $months, $this->getAttributes(), true); - $this->_elements[] =& moodleform::createElement('select','year', null, $years, $this->getAttributes(), true); - $this->_elements[] =& moodleform::createElement('select', 'hour', null, $hours, $this->getAttributes(), true); - $this->_elements[] =& moodleform::createElement('select','minute', null, $minutes, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select', 'day', null, $days, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select','month', null, $months, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select','year', null, $years, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select', 'hour', null, $hours, $this->getAttributes(), true); + $this->_elements[] =& MoodleQuickForm::createElement('select','minute', null, $minutes, $this->getAttributes(), true); } diff --git a/lib/form/file.php b/lib/form/file.php index f877f101d3..db00d12ad5 100644 --- a/lib/form/file.php +++ b/lib/form/file.php @@ -7,7 +7,7 @@ require_once('HTML/QuickForm/file.php'); * @author Jamie Pratt * @access public */ -class moodleform_file extends HTML_QuickForm_file{ +class MoodleQuickForm_file extends HTML_QuickForm_file{ /** * html for help button, if empty then no help * diff --git a/lib/form/group.php b/lib/form/group.php index f4fcc6e614..8c3fcf8f06 100644 --- a/lib/form/group.php +++ b/lib/form/group.php @@ -10,7 +10,7 @@ require_once("HTML/QuickForm/group.php"); * @since PHP4.04pl1 * @access public */ -class moodleform_group extends HTML_QuickForm_group{ +class MoodleQuickForm_group extends HTML_QuickForm_group{ /** * html for help button, if empty then no help * diff --git a/lib/form/hidden.php b/lib/form/hidden.php index ab6ab0ac17..26e50bb334 100644 --- a/lib/form/hidden.php +++ b/lib/form/hidden.php @@ -7,7 +7,7 @@ require_once('HTML/QuickForm/hidden.php'); * @author Jamie Pratt * @access public */ -class moodleform_hidden extends HTML_QuickForm_hidden{ +class MoodleQuickForm_hidden extends HTML_QuickForm_hidden{ /** * html for help button, if empty then no help * diff --git a/lib/form/htmleditor.php b/lib/form/htmleditor.php index 0ecc1f8bed..442dbc619f 100644 --- a/lib/form/htmleditor.php +++ b/lib/form/htmleditor.php @@ -8,13 +8,13 @@ require_once("$CFG->libdir/form/textarea.php"); * @author Jamie Pratt * @access public */ -class moodleform_htmleditor extends moodleform_textarea{ +class MoodleQuickForm_htmleditor extends MoodleQuickForm_textarea{ var $_type; var $_elementTemplateType='default'; var $_canUseHtmlEditor; var $_options=array('canUseHtmlEditor'=>'detect','rows'=>10, 'cols'=>65, 'width'=>0,'height'=>0, 'course'=>0); - function moodleform_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){ - parent::moodleform_textarea($elementName, $elementLabel, $attributes); + function MoodleQuickForm_htmleditor($elementName=null, $elementLabel=null, $options=array(), $attributes=null){ + parent::MoodleQuickForm_textarea($elementName, $elementLabel, $attributes); // set the options, do not bother setting bogus ones if (is_array($options)) { foreach ($options as $name => $value) { diff --git a/lib/form/password.php b/lib/form/password.php index d719da8486..834d853aa6 100644 --- a/lib/form/password.php +++ b/lib/form/password.php @@ -7,7 +7,7 @@ require_once('HTML/QuickForm/password.php'); * @author Jamie Pratt * @access public */ -class moodleform_password extends HTML_QuickForm_password{ +class MoodleQuickForm_password extends HTML_QuickForm_password{ /** * html for help button, if empty then no help * diff --git a/lib/form/radio.php b/lib/form/radio.php index f87638e800..5c9769eec1 100644 --- a/lib/form/radio.php +++ b/lib/form/radio.php @@ -7,7 +7,7 @@ require_once('HTML/QuickForm/radio.php'); * @author Jamie Pratt * @access public */ -class moodleform_radio extends HTML_QuickForm_radio{ +class MoodleQuickForm_radio extends HTML_QuickForm_radio{ /** * html for help button, if empty then no help * diff --git a/lib/form/select.php b/lib/form/select.php index 521ca17bc8..58ae596ce9 100644 --- a/lib/form/select.php +++ b/lib/form/select.php @@ -7,7 +7,7 @@ require_once('HTML/QuickForm/select.php'); * @author Jamie Pratt * @access public */ -class moodleform_select extends HTML_QuickForm_select{ +class MoodleQuickForm_select extends HTML_QuickForm_select{ /** * html for help button, if empty then no help * diff --git a/lib/form/static.php b/lib/form/static.php index 82a6073433..438092183f 100644 --- a/lib/form/static.php +++ b/lib/form/static.php @@ -7,7 +7,7 @@ require_once("HTML/QuickForm/static.php"); * @author Jamie Pratt * @access public */ -class moodleform_static extends HTML_QuickForm_static{ +class MoodleQuickForm_static extends HTML_QuickForm_static{ /** * html for help button, if empty then no help * diff --git a/lib/form/text.php b/lib/form/text.php index d1bf0c4d94..834c9b3cf3 100644 --- a/lib/form/text.php +++ b/lib/form/text.php @@ -7,7 +7,7 @@ require_once("HTML/QuickForm/text.php"); * @author Jamie Pratt * @access public */ -class moodleform_text extends HTML_QuickForm_text{ +class MoodleQuickForm_text extends HTML_QuickForm_text{ /** * html for help button, if empty then no help * diff --git a/lib/form/textarea.php b/lib/form/textarea.php index 2e3450a288..ee3ffb87d5 100644 --- a/lib/form/textarea.php +++ b/lib/form/textarea.php @@ -7,7 +7,7 @@ require_once('HTML/QuickForm/textarea.php'); * @author Jamie Pratt * @access public */ -class moodleform_textarea extends HTML_QuickForm_textarea{ +class MoodleQuickForm_textarea extends HTML_QuickForm_textarea{ /** * html for help button, if empty then no help * diff --git a/lib/formslib.php b/lib/formslib.php index 8d2e6325fa..2bb5070170 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -19,7 +19,115 @@ if ($CFG->debug >= DEBUG_ALL){ PEAR::setErrorHandling(PEAR_ERROR_PRINT); } -class moodleform extends HTML_QuickForm_DHTMLRulesTableless{ +class moodleform { + var $_form; // quickform object definition + var $_customdata; // globals workaround + + function moodleform($action, $customdata=null, $method='post', $target='', $attributes=null) { + $form_name = rtrim(get_class($this), '_form'); + $this->_customdata = $customdata; + $this->_form =& new MoodleQuickForm($form_name, $method, $action, $target, $attributes); + + $this->definition(); + + $this->_form->addElement('hidden', 'sesskey', null); // automatic sesskey protection + $this->_form->setDefault('sesskey', sesskey()); + $this->_form->addElement('hidden', '_qf__', null); // form submission marker + $this->_form->setDefault('_qf__', 1); + + // we have to know all input types before processing submission ;-) + $this->_process_submission($method); + + } + + function _process_submission($method) { + $submission = array(); + if ($method == 'post') { + if (!empty($_POST)) { + $submission = $_POST; + } + } else { + $submission = array_merge_recursive($_GET, $_POST); // emulate handling of parameters in xxxx_param() + } + + // following trick is needed to enable proper sesskey checks when using GET forms + // the _qf__ serves as a marker that form was actually submitted + if (array_key_exists('_qf__', $submission) and $submission['_qf__'] == 1) { + if (!confirm_sesskey()) { + error('Incorrect sesskey submitted, form not accepted!'); + } + } else { + $submission = array(); + } + + $this->_form->updateSubmission($submission); + } + + function set_defaults($default_values, $slashed=false) { + if (is_object($default_values)) { + $default_values = (array)$default_values; + } + $filter = $slashed ? 'stripslashes' : NULL; + $this->_form->setDefaults($default_values, $filter); + } + + function is_submitted() { + return $this->_form->isSubmitted(); + } + + function is_validated() { + static $validated = null; + + if ($validated === null) { + $internal_val = $this->_form->validate(); + $moodle_val = $this->validation($this->_form->exportValues(null, false)); + if ($moodle_val !== true) { + if (!empty($moodle_val)) { + foreach ($moodle_val as $element=>$msg) { + $this->_form->setElementError($element, $msg); + } + } + $moodle_val = false; + } + $validated = ($internal_val and $moodle_val); + } + return $validated; + } + + function data_submitted($slashed=true) { + if ($this->is_submitted() and $this->is_validated()) { + $data = $this->_form->exportValues(null, $slashed); + if (empty($data)) { + return NULL; + } else { + return (object)$data; + } + } else { + return NULL; + } + } + + function display() { + $this->_form->display(); + } + + // abstract method - always override + function definition() { + error('Abstract form_definition() method in class '.get_class($this).' must be overriden, please fix the code.'); + } + + // dummy stub method - override if needed + function validation($data) { + // return array of errors ("fieldname"=>"error message") or true if ok + return true; + } + +} + +class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless { + var $_types = array(); + + /** * Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless * @param string $formName Form's name. @@ -30,88 +138,81 @@ class moodleform extends HTML_QuickForm_DHTMLRulesTableless{ * @param bool $trackSubmit (optional)Whether to track if the form was submitted by adding a special hidden field * @access public */ - function moodleform($formName='', $method='post', $action='', $target='', $attributes=null){ + function MoodleQuickForm($formName, $method, $action, $target='', $attributes=null){ global $CFG; - //we need to override the constructor, we don't call the parent constructor - //at all because it strips slashes depending on the magic quotes setting - //whereas Moodle already has added slashes whether magic quotes is on or not. - - //also added check for sesskey and added sesskey to all forms - //and told class to ask Moodle for the max upload file size + HTML_Common::HTML_Common($attributes); - $method = (strtoupper($method) == 'GET') ? 'get' : 'post'; - $action = ($action == '') ? $_SERVER['PHP_SELF'] : $action; $target = empty($target) ? array() : array('target' => $target); //no 'name' atttribute for form in xhtml strict : $attributes = array('action'=>$action, 'method'=>$method, 'id'=>$formName) + $target; $this->updateAttributes($attributes); - //check for sesskey for this form - //if it is not present then we don't accept any input - if (isset($_REQUEST['_qf__' . $formName])) { - $this->_submitValues = $this->_recursiveFilter('stripslashes', 'get' == $method? $_GET: $_POST); - foreach ($_FILES as $keyFirst => $valFirst) { - foreach ($valFirst as $keySecond => $valSecond) { - if ('name' == $keySecond) { - $this->_submitFiles[$keyFirst][$keySecond] = $this->_recursiveFilter('stripslashes', $valSecond); - } else { - $this->_submitFiles[$keyFirst][$keySecond] = $valSecond; - } - } - } - $this->_flagSubmitted = count($this->_submitValues) > 0 || count($this->_submitFiles) > 0; - } - - //check sesskey - if ($this->_flagSubmitted){ - confirm_sesskey($this->_submitValues['_qf__' . $formName]); - } - unset($this->_submitValues['_qf__' . $formName]); - //add sesskey to all forms - $this->addElement('hidden', '_qf__' . $formName, sesskey()); - - if (preg_match('/^([0-9]+)([a-zA-Z]*)$/', get_max_upload_file_size(), $matches)) { - // see http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes - switch (strtoupper($matches['2'])) { - case 'G': - $this->_maxFileSize = $matches['1'] * 1073741824; - break; - case 'M': - $this->_maxFileSize = $matches['1'] * 1048576; - break; - case 'K': - $this->_maxFileSize = $matches['1'] * 1024; - break; - default: - $this->_maxFileSize = $matches['1']; - } - } - //this is custom stuff for Moodle : + //this is custom stuff for Moodle : $oldclass= $this->getAttribute('class'); if (!empty($oldclass)){ $this->updateAttributes(array('class'=>$oldclass.' mform')); }else { $this->updateAttributes(array('class'=>'mform')); } - $this->_helpImageURL="$CFG->wwwroot/lib/form/req.gif"; - $this->_reqHTML = + $this->_helpImageURL="$CFG->wwwroot/lib/form/req.gif"; + $this->_reqHTML = helpbutton('requiredelement', get_string('requiredelement', 'form'),'moodle', true, false, '', true, ''.get_string('requiredelement', 'form').''); $this->setRequiredNote(get_string('denotesreq', 'form', $this->getReqHTML())); } + + function setType($elementname, $paramtype) { + $this->_types[$elementname] = $paramtype; + } + + function updateSubmission($submission) { + if (empty($submission)) { + $this->_submitValues = array(); + $this->_flagSubmitted = false; + } else { + foreach ($submission as $key=>$s) { + if (array_key_exists($key, $this->_types)) { + $submission[$key] = clean_param($s, $this->_types[$key]); + } + } + $this->_submitValues = $this->_recursiveFilter('stripslashes', $submission); + $this->_flagSubmitted = true; + } + + // need to tell all elements that they need to update their value attribute. + foreach (array_keys($this->_elements) as $key) { + $this->_elements[$key]->onQuickFormEvent('updateValue', null, $this); + } + } + function getReqHTML(){ return $this->_reqHTML; } + + /** + * Initializes a default form value + * + * @param string $elementname element name + * @param mixed $values values for that element name + * @param bool $slashed the default value is slashed + * @access public + * @return void + */ + function setDefault($elementName, $defaultValue, $slashed=false){ + $filter = $slashed ? 'stripslashes' : NULL; + $this->setDefaults(array($elementName=>$defaultValue), $filter); + } // end func setDefault /** * Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless - * @param array $buttons An associative array representing help button to attach to + * @param array $buttons An associative array representing help button to attach to * to the form. keys of array correspond to names of elements in form. - * + * * @access public */ + function setHelpButtons($buttons, $suppresscheck=false){ - + foreach ($this->_elements as $no => $element){ if (array_key_exists($element->getName(), $buttons)){ @@ -125,123 +226,36 @@ class moodleform extends HTML_QuickForm_DHTMLRulesTableless{ } unset($buttons[$element->getName()]); } - + } if (count($buttons)&& !$suppresscheck){ print_error('nonexistentformelements', 'form', '', join(', ', array_keys($buttons))); } } - function acceptGet(){ - $names=func_get_args(); - foreach ($names as $name){ - //if no form data is submitted then the page has just beeen loaded - //so we get the page param value from $_GET - if (!$this->_flagSubmitted && isset($_GET[$name])){ - $this->_submitValues[$name]=$_GET[$name]; - } - } - } - function required_param($element, $paramtype){ - $value = $this->getSubmitValue($element); - if (null !== $value) { - if (false === strpos($element, '[')) { - return $this->_submitValues[$element] = $this->_clean_param($value, $paramtype); - } else { - $idx = "['" . str_replace(array(']', '['), array('', "']['"), $element) . "']"; - eval("return \$this->_submitValues{$idx} = \$this->_clean_param(\$value, \$paramtype);"); - } - }else{ - //could print name of param but better not to for security? - print_error('missingrequiredfield', 'error'); - } - } - function optional_param($element, $default, $paramtype){ - $value = $this->getSubmitValue($element); - if (null === $value) { - return $default; - } - if (false === strpos($element, '[')) { - return $this->_submitValues[$element] = $this->_clean_param($value, $paramtype); - } else { - $idx = "['" . str_replace(array(']', '['), array('', "']['"), $element) . "']"; - eval("return \$this->_submitValues{$idx} = \$this->_clean_param(\$value, \$paramtype);"); - } - } - function clean_param($elementList, $paramtype){ - $value = $this->getSubmitValue($element); - if (false === strpos($element, '[')) { - return $this->_submitValues[$element] = $this->_clean_param($value, $paramtype); - } else { - $idx = "['" . str_replace(array(']', '['), array('', "']['"), $element) . "']"; - eval("return \$this->_submitValues{$idx} = \$this->_clean_param(\$value, \$paramtype);"); - } - } - function _clean_param($value, $paramtype){ - //clean_param function in moodlelib expects vars with slashes - $value=$this->_recursiveFilter('addslashes', $value); - $value=clean_param($value, $paramtype); - return $this->_recursiveFilter('stripslashes', $value); - } - - function exportValue($element, $addslashes=true){ - $unfiltered=parent::exportValue($element); - if ($addslashes){ - return $this->_recursiveFilter('addslashes',$unfiltered); - } else { - return $unfiltered; - } - } + function exportValues($elementList= null, $addslashes=true){ $unfiltered=parent::exportValues($elementList); + unset($unfiltered['sesskey']); // we do not need to return sesskey + unset($unfiltered['_qf__']); // we do not need the submission marker too + if ($addslashes){ return $this->_recursiveFilter('addslashes',$unfiltered); } else { return $unfiltered; } } - /** - * Initializes a default form value - * - * @param string $elementname element name - * @param mixed $values values for that element name - * @param mixed $filter (optional) filter(s) to apply to default value - * @access public - * @return void - */ - function setDefault($elementName='', $defaultValue = null, $filter = null){ - $this->setDefaults(array($elementName =>$defaultValue), $filter); - } // end func setDefault - /** - * Returns 'safe' elements' values - * - * Unlike getSubmitValues(), this will return only the values - * corresponding to the elements present in the form. - * This function also runs validate() and returns false if the form doesn't validate - * - * @param mixed Array/string of element names, whose values we want. If not set then return all elements. - * @access public - * @return object An object with property values set to elements' values - * @throws HTML_QuickForm_Error - */ - function data_submitted($elementList = null, $addslashes=true){ - if (!$this->validate()){ - return false; - }else{ - return (object)$this->exportValues($elementList, $addslashes); - } - } } /** - * A renderer for moodleform that only uses XHTML and CSS and no + * A renderer for MoodleQuickForm that only uses XHTML and CSS and no * table tags, extends PEAR class HTML_QuickForm_Renderer_Tableless - * + * * Stylesheet is part of standard theme and should be automatically included. * * @author Jamie Pratt * @license gpl license */ -class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ +class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ /** * Element template array @@ -266,10 +280,11 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ // * @var string // * @access private // */ -// var $_headerTemplate = +// var $_headerTemplate = // "\n\t\t{header}\n\t\t
    "; -// var $_headerTemplate = +// var $_headerTemplate = // "\n\t\t{header}\n\t\t
      "; + /** * Template used when closing a fieldset * @var string @@ -283,9 +298,10 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ * @var string * @access private */ - var $_requiredNoteTemplate = + var $_requiredNoteTemplate = "\n\t\t
      {requiredNote}
      "; - function moodleform_renderer(){ + + function MoodleQuickForm_Renderer(){ // switch next two lines for ol li containers for form items. // $this->_elementTemplates=array('default'=>"\n\t\t
    1. error {type}\">{error}
      {element}
    2. "); $this->_elementTemplates=array('default'=>"\n\t\t
      error {type}\">{error}
      {element}
      ", @@ -293,26 +309,28 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ parent::HTML_QuickForm_Renderer_Tableless(); } + function startForm(&$form){ $this->_reqHTML=$form->getReqHTML(); $this->_elementTemplates=str_replace('{req}', $this->_reqHTML, $this->_elementTemplates); parent::startForm($form); } + function startGroup(&$group, $required, $error){ if (method_exists($group, 'getElementTemplateType')){ $html = $this->_elementTemplates[$group->getElementTemplateType()]; }else{ $html = $this->_elementTemplates['default']; - + } if (method_exists($group, 'getHelpButton')){ $html =str_replace('{help}', $group->getHelpButton(), $html); }else{ $html =str_replace('{help}', '', $html); - + } $html =str_replace('{type}', 'fgroup', $html); - + $this->_templates[$group->getName()]=$html; // Fix for bug in tableless quickforms that didn't allow you to stop a // fieldset before a group of elements. @@ -325,19 +343,20 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ } parent::startGroup($group, $required, $error); } + function renderElement(&$element, $required, $error){ if (method_exists($element, 'getElementTemplateType')){ $html = $this->_elementTemplates[$element->getElementTemplateType()]; }else{ $html = $this->_elementTemplates['default']; - + } $html =str_replace('{type}', 'f'.$element->getType(), $html); if (method_exists($element, 'getHelpButton')){ $html=str_replace('{help}', $element->getHelpButton(), $html); }else{ $html=str_replace('{help}', '', $html); - + } $this->_templates[$element->getName()]=$html; if (!is_null($element->getAttribute('id'))) { @@ -348,50 +367,23 @@ class moodleform_renderer extends HTML_QuickForm_Renderer_Tableless{ $element->updateAttributes(array('id'=>'id_'.$id)); parent::renderElement($element, $required, $error); } - - } -/*class moodleform_filter{ - var $paramtype; - var $default; - function moodleform_filter($paramtype, $default=NULL){ - $this->paramtype=$paramtype; - $this->default=$default; - } - function required_param($value){ - if (isset($value)) { - $param = $value; - } else { - error('A required parameter was missing'); - } - - return $this->clean_param($param); - } - function optional_param($value){ - if (!isset($value)) { - return $this->default; - } - return $this->clean_param($value); - } - -} */ - -$GLOBALS['_HTML_QuickForm_default_renderer']=& new moodleform_renderer(); -moodleform::registerElementType('checkbox', "$CFG->libdir/form/checkbox.php", 'moodleform_checkbox'); -moodleform::registerElementType('file', "$CFG->libdir/form/file.php", 'moodleform_file'); -moodleform::registerElementType('group', "$CFG->libdir/form/group.php", 'moodleform_group'); -moodleform::registerElementType('password', "$CFG->libdir/form/password.php", 'moodleform_password'); -moodleform::registerElementType('radio', "$CFG->libdir/form/radio.php", 'moodleform_radio'); -moodleform::registerElementType('select', "$CFG->libdir/form/select.php", 'moodleform_select'); -moodleform::registerElementType('text', "$CFG->libdir/form/text.php", 'moodleform_text'); -moodleform::registerElementType('textarea', "$CFG->libdir/form/textarea.php", 'moodleform_textarea'); -moodleform::registerElementType('date_selector', "$CFG->libdir/form/dateselector.php", 'moodleform_date_selector'); -moodleform::registerElementType('date_time_selector', "$CFG->libdir/form/datetimeselector.php", 'moodleform_date_time_selector'); -moodleform::registerElementType('htmleditor', "$CFG->libdir/form/htmleditor.php", 'moodleform_htmleditor'); -moodleform::registerElementType('static', "$CFG->libdir/form/static.php", 'moodleform_static'); -moodleform::registerElementType('hidden', "$CFG->libdir/form/hidden.php", 'moodleform_hidden'); +$GLOBALS['_HTML_QuickForm_default_renderer']=& new MoodleQuickForm_Renderer(); +MoodleQuickForm::registerElementType('checkbox', "$CFG->libdir/form/checkbox.php", 'MoodleQuickForm_checkbox'); +MoodleQuickForm::registerElementType('file', "$CFG->libdir/form/file.php", 'MoodleQuickForm_file'); +MoodleQuickForm::registerElementType('group', "$CFG->libdir/form/group.php", 'MoodleQuickForm_group'); +MoodleQuickForm::registerElementType('password', "$CFG->libdir/form/password.php", 'MoodleQuickForm_password'); +MoodleQuickForm::registerElementType('radio', "$CFG->libdir/form/radio.php", 'MoodleQuickForm_radio'); +MoodleQuickForm::registerElementType('select', "$CFG->libdir/form/select.php", 'MoodleQuickForm_select'); +MoodleQuickForm::registerElementType('text', "$CFG->libdir/form/text.php", 'MoodleQuickForm_text'); +MoodleQuickForm::registerElementType('textarea', "$CFG->libdir/form/textarea.php", 'MoodleQuickForm_textarea'); +MoodleQuickForm::registerElementType('date_selector', "$CFG->libdir/form/dateselector.php", 'MoodleQuickForm_date_selector'); +MoodleQuickForm::registerElementType('date_time_selector', "$CFG->libdir/form/datetimeselector.php", 'MoodleQuickForm_date_time_selector'); +MoodleQuickForm::registerElementType('htmleditor', "$CFG->libdir/form/htmleditor.php", 'MoodleQuickForm_htmleditor'); +MoodleQuickForm::registerElementType('static', "$CFG->libdir/form/static.php", 'MoodleQuickForm_static'); +MoodleQuickForm::registerElementType('hidden', "$CFG->libdir/form/hidden.php", 'MoodleQuickForm_hidden'); ?> \ No newline at end of file -- 2.39.5