3 * formslib.php - library of classes for creating forms in Moodle, based on PEAR QuickForms.
5 * To use formslib then you will want to create a new file purpose_form.php eg. edit_form.php
6 * and you want to name your class something like {modulename}_{purpose}_form. Your class will
7 * extend moodleform overriding abstract classes definition and optionally defintion_after_data
10 * See examples of use of this library in course/edit.php and course/edit_form.php
13 * form defintion is used for both printing of form and processing and should be the same
14 * for both or you may lose some submitted data which won't be let through.
15 * you should be using setType for every form element except select, radio or checkbox
16 * elements, these elements clean themselves.
21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
24 //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else.
25 if (FALSE===strstr(ini_get('include_path'), $CFG->libdir
.'/pear' )){
26 ini_set('include_path', $CFG->libdir
.'/pear' . PATH_SEPARATOR
. ini_get('include_path'));
28 require_once 'HTML/QuickForm.php';
29 require_once 'HTML/QuickForm/DHTMLRulesTableless.php';
30 require_once 'HTML/QuickForm/Renderer/Tableless.php';
32 require_once $CFG->libdir
.'/uploadlib.php';
35 * Callback called when PEAR throws an error
37 * @param PEAR_Error $error
39 function pear_handle_error($error){
40 echo '<strong>'.$error->GetMessage().'</strong> '.$error->getUserInfo();
41 echo '<br /> <strong>Backtrace </strong>:';
42 print_object($error->backtrace
);
45 if ($CFG->debug
>= DEBUG_ALL
){
46 PEAR
::setErrorHandling(PEAR_ERROR_CALLBACK
, 'pear_handle_error');
51 * Moodle specific wrapper that separates quickforms syntax from moodle code. You won't directly
52 * use this class you should write a class defintion which extends this class or a more specific
53 * subclass such a moodleform_mod for each form you want to display and/or process with formslib.
55 * You will write your own definition() method which performs the form set up.
58 var $_formname; // form name
60 * quickform object definition
62 * @var MoodleQuickForm
76 var $_upload_manager; //
81 * The constructor function calls the abstract function definition() and it will then
82 * process and clean and attempt to validate incoming data.
84 * It will call your custom validate method to validate data and will also check any rules
85 * you have specified in definition using addRule
87 * The name of the form (id attribute of the form) is automatically generated depending on
88 * the name you gave the class extending moodleform. You should call your class something
91 * @param string $action the action attribute for the form. If empty defaults to auto detect the
93 * @param array $customdata if your form defintion method needs access to data such as $course
94 * $cm, etc. to construct the form definition then pass it in this array. You can
95 * use globals for somethings.
96 * @param string $method if you set this to anything other than 'post' then _GET and _POST will
97 * be merged and used as incoming data to the form.
98 * @param string $target target frame for form submission. You will rarely use this. Don't use
99 * it if you don't need to as the target attribute is deprecated in xhtml
101 * @param mixed $attributes you can pass a string of html attributes here or an array.
104 function moodleform($action=null, $customdata=null, $method='post', $target='', $attributes=null) {
106 $action = strip_querystring(qualified_me());
109 $this->_formname
= get_class($this); // '_form' suffix kept in order to prevent collisions of form id and other element
110 $this->_customdata
= $customdata;
111 $this->_form
=& new MoodleQuickForm($this->_formname
, $method, $action, $target, $attributes);
112 $this->set_upload_manager(new upload_manager());
116 $this->_form
->addElement('hidden', 'sesskey', null); // automatic sesskey protection
117 $this->_form
->setDefault('sesskey', sesskey());
118 $this->_form
->addElement('hidden', '_qf__'.$this->_formname
, null); // form submission marker
119 $this->_form
->setDefault('_qf__'.$this->_formname
, 1);
120 $this->_form
->_setDefaultRuleMessages();
122 // we have to know all input types before processing submission ;-)
123 $this->_process_submission($method);
125 // update form definition based on final data
126 $this->definition_after_data();
130 * To autofocus on first form element or first element with error.
132 * @param string $name if this is set then the focus is forced to a field with this name
134 * @return string javascript to select form element with first error or
135 * first element if no errors. Use this as a parameter
136 * when calling print_header
138 function focus($name=NULL){
139 $form =& $this->_form
;
140 $elkeys=array_keys($form->_elementIndex
);
141 if (isset($form->_errors
) && 0 != count($form->_errors
)){
142 $errorkeys = array_keys($form->_errors
);
143 $elkeys = array_intersect($elkeys, $errorkeys);
147 $el = array_shift($elkeys);
148 $names = $form->_getElNamesRecursive($el);
151 $name=array_shift($names);
153 $focus='forms[\''.$this->_form
->getAttribute('id').'\'].elements[\''.$name.'\']';
158 * Internal method. Alters submitted data to be suitable for quickforms processing.
159 * Must be called when the form is fully set up.
161 function _process_submission($method) {
162 $submission = array();
163 if ($method == 'post') {
164 if (!empty($_POST)) {
165 $submission = $_POST;
168 $submission = array_merge_recursive($_GET, $_POST); // emulate handling of parameters in xxxx_param()
171 // following trick is needed to enable proper sesskey checks when using GET forms
172 // the _qf__.$this->_formname serves as a marker that form was actually submitted
173 if (array_key_exists('_qf__'.$this->_formname
, $submission) and $submission['_qf__'.$this->_formname
] == 1) {
174 if (!confirm_sesskey()) {
175 error('Incorrect sesskey submitted, form not accepted!');
179 $submission = array();
183 $this->_form
->updateSubmission($submission, $files);
187 * Internal method. Validates all uploaded files.
189 function _validate_files() {
190 if (empty($_FILES)) {
191 // we do not need to do any checks because no files were submitted
192 // TODO: find out why server side required rule does not work for uploaded files;
193 // testing is easily done by always returning true from this function and adding
194 // $mform->addRule('soubor', get_string('required'), 'required', null, 'server');
195 // and submitting form without selected file
199 $mform =& $this->_form
;
202 $status = $this->_upload_manager
->preprocess_files();
204 // now check that we really want each file
205 foreach ($_FILES as $elname=>$file) {
206 if ($mform->elementExists($elname) and $mform->getElementType($elname)=='file') {
207 $required = $mform->isElementRequired($elname);
208 if (!empty($this->_upload_manager
->files
[$elname]['uploadlog']) and empty($this->_upload_manager
->files
[$elname]['clear'])) {
209 if (!$required and $file['error'] == UPLOAD_ERR_NO_FILE
) {
210 // file not uploaded and not required - ignore it
213 $errors[$elname] = $this->_upload_manager
->files
[$elname]['uploadlog'];
216 error('Incorrect upload attempt!');
220 // return errors if found
221 if ($status and 0 == count($errors)){
229 * Load in existing data as form defaults. Usually new entry defaults are stored directly in
230 * form definition (new entry form); this function is used to load in data where values
231 * already exist and data is being edited (edit entry form).
233 * @param mixed $default_values object or array of default values
234 * @param bool $slased true if magic quotes applied to data values
236 function set_data($default_values, $slashed=false) {
237 if (is_object($default_values)) {
238 $default_values = (array)$default_values;
240 $filter = $slashed ?
'stripslashes' : NULL;
241 $this->_form
->setDefaults($default_values, $filter);
242 //update form definition when data changed
243 $this->definition_after_data();
247 * Set custom upload manager.
248 * Must be used BEFORE creating of file element!
250 * @param object $um - custom upload manager
252 function set_upload_manager($um=false) {
254 $um = new upload_manager();
256 $this->_upload_manager
= $um;
258 $this->_form
->setMaxFileSize($um->config
->maxbytes
);
262 * Check that form was submitted. Does not check validity of submitted data.
264 * @return bool true if form properly submitted
266 function is_submitted() {
267 return $this->_form
->isSubmitted();
270 function no_submit_button_pressed(){
271 static $nosubmit = null; // one check is enough
272 if (!is_null($nosubmit)){
275 $mform =& $this->_form
;
277 if (!$this->is_submitted()){
280 foreach ($mform->_noSubmitButtons
as $nosubmitbutton){
281 if (optional_param($nosubmitbutton, 0, PARAM_RAW
)){
291 * Check that form data is valid.
293 * @return bool true if form data valid
295 function is_validated() {
296 static $validated = null; // one validation is enough
297 $mform =& $this->_form
;
299 if ($this->no_submit_button_pressed()){
301 } elseif ($validated === null) {
302 $internal_val = $mform->validate();
303 $moodle_val = $this->validation($mform->exportValues(null, true));
304 if ($moodle_val !== true) {
305 if ((is_array($moodle_val) && count($moodle_val)!==0)) {
306 foreach ($moodle_val as $element=>$msg) {
307 $mform->setElementError($element, $msg);
314 $file_val = $this->_validate_files();
315 if ($file_val !== true) {
316 if (!empty($file_val)) {
317 foreach ($file_val as $element=>$msg) {
318 $mform->setElementError($element, $msg);
323 $validated = ($internal_val and $moodle_val and $file_val);
329 * Return true if a cancel button has been pressed resulting in the form being submitted.
331 * @return boolean true if a cancel button has been pressed
333 function is_cancelled(){
334 $mform =& $this->_form
;
335 if ($mform->isSubmitted()){
336 foreach ($mform->_cancelButtons
as $cancelbutton){
337 if (optional_param($cancelbutton, 0, PARAM_RAW
)){
346 * Return submitted data if properly submitted or returns NULL if validation fails or
347 * if there is no submitted data.
349 * @param bool $slashed true means return data with addslashes applied
350 * @return object submitted data; NULL if not valid or not submitted
352 function get_data($slashed=true) {
353 $mform =& $this->_form
;
355 if ($this->is_submitted() and $this->is_validated()) {
356 $data = $mform->exportValues(null, $slashed);
357 unset($data['sesskey']); // we do not need to return sesskey
358 unset($data['_qf__'.$this->_formname
]); // we do not need the submission marker too
362 return (object)$data;
370 * Save verified uploaded files into directory. Upload process can be customised from definition()
371 * method by creating instance of upload manager and storing it in $this->_upload_form
373 * @param string $destination where to store uploaded files
374 * @return bool success
376 function save_files($destination) {
377 if ($this->is_submitted() and $this->is_validated()) {
378 return $this->_upload_manager
->save_files($destination);
384 * If we're only handling one file (if inputname was given in the constructor)
385 * this will return the (possibly changed) filename of the file.
386 * @return mixed false in case of failure, string if ok
388 function get_new_filename() {
389 return $this->_upload_manager
->get_new_filename();
396 $this->_form
->display();
400 * Abstract method - always override!
402 * If you need special handling of uploaded files, create instance of $this->_upload_manager here.
404 function definition() {
405 error('Abstract form_definition() method in class '.get_class($this).' must be overriden, please fix the code.');
409 * Dummy stub method - override if you need to setup the form depending on current
410 * values. This method is called after definition(), data submission and set_data().
411 * All form setup that is dependent on form values should go in here.
413 function definition_after_data(){
417 * Dummy stub method - override if you needed to perform some extra validation.
418 * If there are errors return array of errors ("fieldname"=>"error message"),
419 * otherwise true if ok.
421 * @param array $data array of ("fieldname"=>value) of submitted data
422 * @return bool array of errors or true if ok
424 function validation($data) {
433 * Method to add a repeating group of elements to a form.
435 * @param array $elementobjs Array of elements or groups of elements that are to be repeated
436 * @param integer $repeats no of times to repeat elements initially
437 * @param array $options Array of options to apply to elements. Array keys are element names.
438 * This is an array of arrays. The second sets of keys are the option types
440 * 'default' - default value is value
441 * 'type' - PARAM_* constant is value
442 * 'helpbutton' - helpbutton params array is value
443 * 'disabledif' - last three moodleform::disabledIf()
444 * params are value as an array
445 * @param string $repeathiddenname name for hidden element storing no of repeats in this form
446 * @param string $addfieldsname name for button to add more fields
447 * @param int $addfieldsno how many fields to add at a time
448 * @param string $addstring name of button, {no} is replaced by no of blanks that will be added.
449 * @return int no of repeats of element in this page
451 function repeat_elements($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=null){
452 if ($addstring===null){
453 $addstring = get_string('addfields', 'form', $addfieldsno);
455 $addstring = str_ireplace('{no}', $addfieldsno, $addstring);
457 $repeats = optional_param($repeathiddenname, $repeats, PARAM_INT
);
458 $addfields = optional_param($addfieldsname, '', PARAM_TEXT
);
459 if (!empty($addfields)){
460 $repeats +
= $addfieldsno;
462 $mform =& $this->_form
;
463 $mform->registerNoSubmitButton($addfieldsname);
464 $mform->addElement('hidden', $repeathiddenname, $repeats);
465 //value not to be overridden by submitted value
466 $mform->setConstants(array($repeathiddenname=>$repeats));
467 for ($i=0; $i<$repeats; $i++
) {
468 foreach ($elementobjs as $elementobj){
469 $elementclone = clone($elementobj);
470 $name = $elementclone->getName();
472 $elementclone->setName($name."[$i]");
474 if (is_a($elementclone, 'HTML_QuickForm_header')){
475 $value=$elementclone->_text
;
476 $elementclone->setValue(str_replace('{no}', ($i+
1), $value));
479 $value=$elementclone->getLabel();
480 $elementclone->setLabel(str_replace('{no}', ($i+
1), $value));
484 $mform->addElement($elementclone);
487 for ($i=0; $i<$repeats; $i++
) {
488 foreach ($options as $elementname => $elementoptions){
489 $pos=strpos($elementname, '[');
491 $realelementname = substr($elementname, 0, $pos+
1)."[$i]";
492 $realelementname .= substr($elementname, $pos+
1);
494 $realelementname = $elementname."[$i]";
496 foreach ($elementoptions as $option => $params){
500 $mform->setDefault($realelementname, $params);
503 $mform->setHelpButton($realelementname, $params);
506 $params = array_merge(array($realelementname), $params);
507 call_user_func_array(array(&$mform, 'disabledIf'), $params);
510 if (is_string($params)){
511 $params = array(null, $params, null, 'client');
513 $params = array_merge(array($realelementname), $params);
514 call_user_func_array(array(&$mform, 'addRule'), $params);
521 $mform->addElement('submit', $addfieldsname, $addstring);
523 $mform->closeHeaderBefore($addfieldsname);
528 * Use this method to a cancel and submit button to the end of your form. Pass a param of false
529 * if you don't want a cancel button in your form. If you have a cancel button make sure you
530 * check for it being pressed using is_cancelled() and redirecting if it is true before trying to
531 * get data with get_data().
533 * @param boolean $cancel whether to show cancel button, default true
534 * @param boolean $revert whether to show revert button, default true
535 * @param string $submitlabel label for submit button, defaults to get_string('savechanges')
537 function add_action_buttons($cancel = true, $submitlabel=null){
538 if (is_null($submitlabel)){
539 $submitlabel = get_string('savechanges');
541 $mform =& $this->_form
;
543 //when two elements we need a group
544 $buttonarray=array();
545 $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
546 $buttonarray[] = &$mform->createElement('cancel');
547 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
548 $mform->closeHeaderBefore('buttonar');
551 $mform->addElement('submit', 'submitbutton', $submitlabel);
552 $mform->closeHeaderBefore('submitbutton');
558 * You never extend this class directly. The class methods of this class are available from
559 * the private $this->_form property on moodleform and it's children. You generally only
560 * call methods on this class from within abstract methods that you override on moodleform such
561 * as definition and definition_after_data
564 class MoodleQuickForm
extends HTML_QuickForm_DHTMLRulesTableless
{
565 var $_types = array();
566 var $_dependencies = array();
568 * Array of buttons that if pressed do not result in the processing of the form.
572 var $_noSubmitButtons=array();
574 * Array of buttons that if pressed do not result in the processing of the form.
578 var $_cancelButtons=array();
581 * Array whose keys are element names. If the key exists this is a advanced element
585 var $_advancedElements = array();
588 * Whether to display advanced elements (on page load)
592 var $_showAdvanced = null;
595 * The form name is derrived from the class name of the wrapper minus the trailing form
596 * It is a name with words joined by underscores whereas the id attribute is words joined by
604 * Class constructor - same parameters as HTML_QuickForm_DHTMLRulesTableless
605 * @param string $formName Form's name.
606 * @param string $method (optional)Form's method defaults to 'POST'
607 * @param string $action (optional)Form's action
608 * @param string $target (optional)Form's target defaults to none
609 * @param mixed $attributes (optional)Extra attributes for <form> tag
610 * @param bool $trackSubmit (optional)Whether to track if the form was submitted by adding a special hidden field
613 function MoodleQuickForm($formName, $method, $action, $target='', $attributes=null){
616 static $formcounter = 1;
618 HTML_Common
::HTML_Common($attributes);
619 $target = empty($target) ?
array() : array('target' => $target);
620 $this->_formName
= $formName;
621 //no 'name' atttribute for form in xhtml strict :
622 $attributes = array('action'=>$action, 'method'=>$method, 'id'=>'mform'.$formcounter) +
$target;
624 $this->updateAttributes($attributes);
626 //this is custom stuff for Moodle :
627 $oldclass= $this->getAttribute('class');
628 if (!empty($oldclass)){
629 $this->updateAttributes(array('class'=>$oldclass.' mform'));
631 $this->updateAttributes(array('class'=>'mform'));
633 $this->_reqHTML
= '<img class="req" alt="'.get_string('requiredelement', 'form').'" src="'.$CFG->pixpath
.'/req.gif'.'" />';
634 $this->_advancedHTML
= '<img class="adv" alt="'.get_string('advancedelement', 'form').'" src="'.$CFG->pixpath
.'/adv.gif'.'" />';
635 $this->setRequiredNote(get_string('somefieldsrequired', 'form').
636 helpbutton('requiredelement', get_string('requiredelement', 'form'), 'moodle', true, false, '', true));
640 * Use this method to indicate an element in a form is an advanced field. If items in a form
641 * are marked as advanced then 'Hide/Show Advanced' buttons will automatically be displayed in the
642 * form so the user can decide whether to display advanced form controls.
644 * If you set a header element to advanced then all elements it contains will also be set as advanced.
646 * @param string $elementName group or element name (not the element name of something inside a group).
647 * @param boolean $advanced default true sets the element to advanced. False removes advanced mark.
649 function setAdvanced($elementName, $advanced=true){
651 $this->_advancedElements
[$elementName]='';
652 } elseif (isset($this->_advancedElements
[$elementName])) {
653 unset($this->_advancedElements
[$elementName]);
655 if ($advanced && $this->getElementType('mform_showadvanced_last')===false){
656 $this->setShowAdvanced();
657 $this->registerNoSubmitButton('mform_showadvanced');
659 $this->addElement('hidden', 'mform_showadvanced_last');
663 * Set whether to show advanced elements in the form on first displaying form. Default is not to
664 * display advanced elements in the form until 'Show Advanced' is pressed.
666 * You can get the last state of the form and possibly save it for this user by using
667 * value 'mform_showadvanced_last' in submitted data.
669 * @param boolean $showadvancedNow
671 function setShowAdvanced($showadvancedNow = null){
672 if ($showadvancedNow === null){
673 if ($this->_showAdvanced
!== null){
675 } else { //if setShowAdvanced is called without any preference
676 //make the default to not show advanced elements.
677 $showadvancedNow = get_user_preferences(
678 moodle_strtolower($this->_formName
.'_showadvanced', 0));
681 //value of hidden element
682 $hiddenLast = optional_param('mform_showadvanced_last', -1, PARAM_INT
);
684 $buttonPressed = optional_param('mform_showadvanced', 0, PARAM_RAW
);
685 //toggle if button pressed or else stay the same
686 if ($hiddenLast == -1) {
687 $next = $showadvancedNow;
688 } elseif ($buttonPressed) { //toggle on button press
689 $next = !$hiddenLast;
693 $this->_showAdvanced
= $next;
694 if ($showadvancedNow != $next){
695 set_user_preference($this->_formName
.'_showadvanced', $next);
697 $this->setConstants(array('mform_showadvanced_last'=>$next));
699 function getShowAdvanced(){
700 return $this->_showAdvanced
;
707 * @param HTML_QuickForm_Renderer An HTML_QuickForm_Renderer object
712 function accept(&$renderer)
714 if (method_exists($renderer, 'setAdvancedElements')){
715 //check for visible fieldsets where all elements are advanced
716 //and mark these headers as advanced as well.
717 //And mark all elements in a advanced header as advanced
718 $stopFields = $renderer->getStopFieldSetElements();
720 $lastHeaderAdvanced = false;
721 $anyAdvanced = false;
722 foreach (array_keys($this->_elements
) as $elementIndex){
723 $element =& $this->_elements
[$elementIndex];
724 if ($element->getType()=='header' ||
in_array($element->getName(), $stopFields)){
725 if ($anyAdvanced && ($lastHeader!==null)){
726 $this->setAdvanced($lastHeader->getName());
728 $lastHeaderAdvanced = false;
729 } elseif ($lastHeaderAdvanced) {
730 $this->setAdvanced($element->getName());
732 if ($element->getType()=='header'){
733 $lastHeader =& $element;
734 $anyAdvanced = false;
735 $lastHeaderAdvanced = isset($this->_advancedElements
[$element->getName()]);
736 } elseif (isset($this->_advancedElements
[$element->getName()])){
740 $renderer->setAdvancedElements($this->_advancedElements
);
743 parent
::accept($renderer);
748 function closeHeaderBefore($elementName){
749 $renderer =& $this->defaultRenderer();
750 $renderer->addStopFieldsetElements($elementName);
754 * Should be used for all elements of a form except for select, radio and checkboxes which
755 * clean their own data.
757 * @param string $elementname
758 * @param integer $paramtype use the constants PARAM_*.
759 * * PARAM_CLEAN is deprecated and you should try to use a more specific type.
760 * * PARAM_TEXT should be used for cleaning data that is expected to be plain text.
761 * It will strip all html tags. But will still let tags for multilang support
763 * * PARAM_RAW means no cleaning whatsoever, it is used mostly for data from the
764 * html editor. Data from the editor is later cleaned before display using
765 * format_text() function. PARAM_RAW can also be used for data that is validated
766 * by some other way or printed by p() or s().
767 * * PARAM_INT should be used for integers.
768 * * PARAM_ACTION is an alias of PARAM_ALPHA and is used for hidden fields specifying
771 function setType($elementname, $paramtype) {
772 $this->_types
[$elementname] = $paramtype;
776 * See description of setType above. This can be used to set several types at once.
778 * @param array $paramtypes
780 function setTypes($paramtypes) {
781 $this->_types
= $paramtypes +
$this->_types
;
784 function updateSubmission($submission, $files) {
785 $this->_flagSubmitted
= false;
787 if (empty($submission)) {
788 $this->_submitValues
= array();
790 foreach ($submission as $key=>$s) {
791 if (array_key_exists($key, $this->_types
)) {
792 $submission[$key] = clean_param($s, $this->_types
[$key]);
795 $this->_submitValues
= $this->_recursiveFilter('stripslashes', $submission);
796 $this->_flagSubmitted
= true;
800 $this->_submitFiles
= array();
802 if (1 == get_magic_quotes_gpc()) {
803 foreach (array_keys($files) as $elname) {
804 // dangerous characters in filenames are cleaned later in upload_manager
805 $files[$elname]['name'] = stripslashes($files[$elname]['name']);
808 $this->_submitFiles
= $files;
809 $this->_flagSubmitted
= true;
812 // need to tell all elements that they need to update their value attribute.
813 foreach (array_keys($this->_elements
) as $key) {
814 $this->_elements
[$key]->onQuickFormEvent('updateValue', null, $this);
818 function getReqHTML(){
819 return $this->_reqHTML
;
822 function getAdvancedHTML(){
823 return $this->_advancedHTML
;
827 * Initializes a default form value. Used to specify the default for a new entry where
828 * no data is loaded in using moodleform::set_data()
830 * @param string $elementname element name
831 * @param mixed $values values for that element name
832 * @param bool $slashed the default value is slashed
836 function setDefault($elementName, $defaultValue, $slashed=false){
837 $filter = $slashed ?
'stripslashes' : NULL;
838 $this->setDefaults(array($elementName=>$defaultValue), $filter);
839 } // end func setDefault
841 * Add an array of buttons to the form
842 * @param array $buttons An associative array representing help button to attach to
843 * to the form. keys of array correspond to names of elements in form.
847 function setHelpButtons($buttons, $suppresscheck=false, $function='helpbutton'){
849 foreach ($buttons as $elementname => $button){
850 $this->setHelpButton($elementname, $button, $suppresscheck, $function);
854 * Add a single button.
856 * @param string $elementname name of the element to add the item to
857 * @param array $button - arguments to pass to function $function
858 * @param boolean $suppresscheck - whether to throw an error if the element
860 * @param string $function - function to generate html from the arguments in $button
862 function setHelpButton($elementname, $button, $suppresscheck=false, $function='helpbutton'){
863 if (array_key_exists($elementname, $this->_elementIndex
)){
864 //_elements has a numeric index, this code accesses the elements by name
865 $element=&$this->_elements
[$this->_elementIndex
[$elementname]];
866 if (method_exists($element, 'setHelpButton')){
867 $element->setHelpButton($button, $function);
870 $a->name
=$element->getName();
871 $a->classname
=get_class($element);
872 print_error('nomethodforaddinghelpbutton', 'form', '', $a);
874 }elseif (!$suppresscheck){
875 print_error('nonexistentformelements', 'form', '', $elementname);
879 function exportValues($elementList= null, $addslashes=true){
880 $unfiltered = array();
881 if (null === $elementList) {
882 // iterate over all elements, calling their exportValue() methods
883 $emptyarray = array();
884 foreach (array_keys($this->_elements
) as $key) {
885 if ($this->_elements
[$key]->isFrozen() && !$this->_elements
[$key]->_persistantFreeze
){
886 $value = $this->_elements
[$key]->exportValue($emptyarray, true);
888 $value = $this->_elements
[$key]->exportValue($this->_submitValues
, true);
891 if (is_array($value)) {
892 // This shit throws a bogus warning in PHP 4.3.x
893 $unfiltered = HTML_QuickForm
::arrayMerge($unfiltered, $value);
897 if (!is_array($elementList)) {
898 $elementList = array_map('trim', explode(',', $elementList));
900 foreach ($elementList as $elementName) {
901 $value = $this->exportValue($elementName);
902 if (PEAR
::isError($value)) {
905 $unfiltered[$elementName] = $value;
910 return $this->_recursiveFilter('addslashes', $unfiltered);
916 * Adds a validation rule for the given field
918 * If the element is in fact a group, it will be considered as a whole.
919 * To validate grouped elements as separated entities,
920 * use addGroupRule instead of addRule.
922 * @param string $element Form element name
923 * @param string $message Message to display for invalid data
924 * @param string $type Rule type, use getRegisteredRules() to get types
925 * @param string $format (optional)Required for extra rule data
926 * @param string $validation (optional)Where to perform validation: "server", "client"
927 * @param boolean $reset Client-side validation: reset the form element to its original value if there is an error?
928 * @param boolean $force Force the rule to be applied, even if the target form element does not exist
931 * @throws HTML_QuickForm_Error
933 function addRule($element, $message, $type, $format=null, $validation='server', $reset = false, $force = false)
935 parent
::addRule($element, $message, $type, $format, $validation, $reset, $force);
936 if ($validation == 'client') {
937 $this->updateAttributes(array('onsubmit' => 'try { var myValidator = validate_' . $this->_formName
. '; } catch(e) { return true; } return myValidator(this);'));
940 } // end func addRule
942 * Adds a validation rule for the given group of elements
944 * Only groups with a name can be assigned a validation rule
945 * Use addGroupRule when you need to validate elements inside the group.
946 * Use addRule if you need to validate the group as a whole. In this case,
947 * the same rule will be applied to all elements in the group.
948 * Use addRule if you need to validate the group against a function.
950 * @param string $group Form group name
951 * @param mixed $arg1 Array for multiple elements or error message string for one element
952 * @param string $type (optional)Rule type use getRegisteredRules() to get types
953 * @param string $format (optional)Required for extra rule data
954 * @param int $howmany (optional)How many valid elements should be in the group
955 * @param string $validation (optional)Where to perform validation: "server", "client"
956 * @param bool $reset Client-side: whether to reset the element's value to its original state if validation failed.
959 * @throws HTML_QuickForm_Error
961 function addGroupRule($group, $arg1, $type='', $format=null, $howmany=0, $validation = 'server', $reset = false)
963 parent
::addGroupRule($group, $arg1, $type, $format, $howmany, $validation, $reset);
964 if (is_array($arg1)) {
965 foreach ($arg1 as $rules) {
966 foreach ($rules as $rule) {
967 $validation = (isset($rule[3]) && 'client' == $rule[3])?
'client': 'server';
969 if ('client' == $validation) {
970 $this->updateAttributes(array('onsubmit' => 'try { var myValidator = validate_' . $this->_formName
. '; } catch(e) { return true; } return myValidator(this);'));
974 } elseif (is_string($arg1)) {
976 if ($validation == 'client') {
977 $this->updateAttributes(array('onsubmit' => 'try { var myValidator = validate_' . $this->_formName
. '; } catch(e) { return true; } return myValidator(this);'));
980 } // end func addGroupRule
984 * Returns the client side validation script
986 * The code here was copied from HTML_QuickForm_DHTMLRulesTableless who copied it from HTML_QuickForm
987 * and slightly modified to run rules per-element
988 * Needed to override this because of an error with client side validation of grouped elements.
991 * @return string Javascript to perform validation, empty string if no 'client' rules were added
993 function getValidationScript()
995 if (empty($this->_rules
) ||
empty($this->_attributes
['onsubmit'])) {
999 include_once('HTML/QuickForm/RuleRegistry.php');
1000 $registry =& HTML_QuickForm_RuleRegistry
::singleton();
1011 foreach ($this->_rules
as $elementName => $rules) {
1012 foreach ($rules as $rule) {
1013 if ('client' == $rule['validation']) {
1014 unset($element); //TODO: find out how to properly initialize it
1016 $dependent = isset($rule['dependent']) && is_array($rule['dependent']);
1017 $rule['message'] = strtr($rule['message'], $js_escape);
1019 if (isset($rule['group'])) {
1020 $group =& $this->getElement($rule['group']);
1021 // No JavaScript validation for frozen elements
1022 if ($group->isFrozen()) {
1025 $elements =& $group->getElements();
1026 foreach (array_keys($elements) as $key) {
1027 if ($elementName == $group->getElementName($key)) {
1028 $element =& $elements[$key];
1032 } elseif ($dependent) {
1034 $element[] =& $this->getElement($elementName);
1035 foreach ($rule['dependent'] as $elName) {
1036 $element[] =& $this->getElement($elName);
1039 $element =& $this->getElement($elementName);
1041 // No JavaScript validation for frozen elements
1042 if (is_object($element) && $element->isFrozen()) {
1044 } elseif (is_array($element)) {
1045 foreach (array_keys($element) as $key) {
1046 if ($element[$key]->isFrozen()) {
1051 // Fix for bug displaying errors for elements in a group
1052 //$test[$elementName][] = $registry->getValidationScript($element, $elementName, $rule);
1053 $test[$elementName][0][] = $registry->getValidationScript($element, $elementName, $rule);
1054 $test[$elementName][1]=$element;
1060 <script type="text/javascript">
1063 var skipClientValidation = false;
1065 function qf_errorHandler(element, _qfMsg) {
1066 div = element.parentNode;
1067 if (_qfMsg != \'\') {
1068 var errorSpan = document.getElementById(\'id_error_\'+element.name);
1070 errorSpan = document.createElement("span");
1071 errorSpan.id = \'id_error_\'+element.name;
1072 errorSpan.className = "error";
1073 element.parentNode.insertBefore(errorSpan, element.parentNode.firstChild);
1076 while (errorSpan.firstChild) {
1077 errorSpan.removeChild(errorSpan.firstChild);
1080 errorSpan.appendChild(document.createTextNode(_qfMsg.substring(3)));
1081 errorSpan.appendChild(document.createElement("br"));
1083 if (div.className.substr(div.className.length - 6, 6) != " error"
1084 && div.className != "error") {
1085 div.className += " error";
1090 var errorSpan = document.getElementById(\'id_error_\'+element.name);
1092 errorSpan.parentNode.removeChild(errorSpan);
1095 if (div.className.substr(div.className.length - 6, 6) == " error") {
1096 div.className = div.className.substr(0, div.className.length - 6);
1097 } else if (div.className == "error") {
1105 foreach ($test as $elementName => $jsandelement) {
1106 // Fix for bug displaying errors for elements in a group
1108 list($jsArr,$element)=$jsandelement;
1111 function validate_' . $this->_formName
. '_' . $elementName . '(element) {
1113 var errFlag = new Array();
1116 var frm = element.parentNode;
1117 while (frm && frm.nodeName != "FORM") {
1118 frm = frm.parentNode;
1120 ' . join("\n", $jsArr) . '
1121 return qf_errorHandler(element, _qfMsg);
1125 ret = validate_' . $this->_formName
. '_' . $elementName.'(frm.elements[\''.$elementName.'\']) && ret;
1126 if (!ret && !first_focus) {
1128 frm.elements[\''.$elementName.'\'].focus();
1132 // Fix for bug displaying errors for elements in a group
1134 //$element =& $this->getElement($elementName);
1136 $valFunc = 'validate_' . $this->_formName
. '_' . $elementName . '(this)';
1137 $onBlur = $element->getAttribute('onBlur');
1138 $onChange = $element->getAttribute('onChange');
1139 $element->updateAttributes(array('onBlur' => $onBlur . $valFunc,
1140 'onChange' => $onChange . $valFunc));
1142 // do not rely on frm function parameter, because htmlarea breaks it when overloading the onsubmit method
1144 function validate_' . $this->_formName
. '(frm) {
1145 if (skipClientValidation) {
1150 var frm = document.getElementById(\''. $this->_attributes
['id'] .'\')
1151 var first_focus = false;
1152 ' . $validateJS . ';
1158 } // end func getValidationScript
1159 function _setDefaultRuleMessages(){
1160 foreach ($this->_rules
as $field => $rulesarr){
1161 foreach ($rulesarr as $key => $rule){
1162 if ($rule['message']===null){
1164 $a->format
=$rule['format'];
1165 $str=get_string('err_'.$rule['type'], 'form', $a);
1166 if (strpos($str, '[[')!==0){
1167 $this->_rules
[$field][$key]['message']=$str;
1174 function getLockOptionEndScript(){
1176 $iname = $this->getAttribute('id').'items';
1177 $js = '<script type="text/javascript">'."\n";
1178 $js .= '//<![CDATA['."\n";
1179 $js .= "var $iname = Array();\n";
1181 foreach ($this->_dependencies
as $dependentOn => $conditions){
1182 $js .= "{$iname}['$dependentOn'] = Array();\n";
1183 foreach ($conditions as $condition=>$values) {
1184 $js .= "{$iname}['$dependentOn']['$condition'] = Array();\n";
1185 foreach ($values as $value=>$dependents) {
1186 $js .= "{$iname}['$dependentOn']['$condition']['$value'] = Array();\n";
1188 foreach ($dependents as $dependent) {
1189 $elements = $this->_getElNamesRecursive($dependent);
1190 foreach($elements as $element) {
1191 if ($element == $dependentOn) {
1194 $js .= "{$iname}['$dependentOn']['$condition']['$value'][$i]='$element';\n";
1201 $js .="lockoptionsallsetup('".$this->getAttribute('id')."');\n";
1203 $js .='</script>'."\n";
1207 function _getElNamesRecursive($element, $group=null){
1209 $el = $this->getElement($element);
1213 if (is_a($el, 'HTML_QuickForm_group')){
1215 $elsInGroup = $group->getElements();
1217 foreach ($elsInGroup as $elInGroup){
1218 $elNames = array_merge($elNames, $this->_getElNamesRecursive($elInGroup, $group));
1221 if ($group != null){
1222 $elNames = array($group->getElementName($el->getName()));
1223 } elseif (is_a($el, 'HTML_QuickForm_header')) {
1225 } elseif (is_a($el, 'HTML_QuickForm_hidden')) {
1227 } elseif (method_exists($el, 'getPrivateName')) {
1228 return array($el->getPrivateName());
1230 $elNames = array($el->getName());
1237 * Adds a dependency for $elementName which will be disabled if $condition is met.
1238 * If $condition = 'notchecked' (default) then the condition is that the $dependentOn element
1239 * is not checked. If $condition = 'checked' then the condition is that the $dependentOn element
1240 * is checked. If $condition is something else then it is checked to see if the value
1241 * of the $dependentOn element is equal to $condition.
1243 * @param string $elementName the name of the element which will be disabled
1244 * @param string $dependentOn the name of the element whose state will be checked for
1246 * @param string $condition the condition to check
1247 * @param mixed $value used in conjunction with condition.
1249 function disabledIf($elementName, $dependentOn, $condition = 'notchecked', $value='1'){
1250 if (!array_key_exists($dependentOn, $this->_dependencies
)) {
1251 $this->_dependencies
[$dependentOn] = array();
1253 if (!array_key_exists($condition, $this->_dependencies
[$dependentOn])) {
1254 $this->_dependencies
[$dependentOn][$condition] = array();
1256 if (!array_key_exists($value, $this->_dependencies
[$dependentOn][$condition])) {
1257 $this->_dependencies
[$dependentOn][$condition][$value] = array();
1259 $this->_dependencies
[$dependentOn][$condition][$value][] = $elementName;
1262 function registerNoSubmitButton($buttonname){
1263 $this->_noSubmitButtons
[]=$buttonname;
1266 function isNoSubmitButton($buttonname){
1267 return (array_search($buttonname, $this->_noSubmitButtons
)!==FALSE);
1270 function _registerCancelButton($addfieldsname){
1271 $this->_cancelButtons
[]=$addfieldsname;
1274 * Displays elements without HTML input tags.
1275 * This method is different to freeze() in that it makes sure no hidden
1276 * elements are included in the form. And a 'hardFrozen' element's submitted value is
1279 * This function also removes all previously defined rules.
1281 * @param mixed $elementList array or string of element(s) to be frozen
1284 * @throws HTML_QuickForm_Error
1286 function hardFreeze($elementList=null)
1288 if (!isset($elementList)) {
1289 $this->_freezeAll
= true;
1290 $elementList = array();
1292 if (!is_array($elementList)) {
1293 $elementList = preg_split('/[ ]*,[ ]*/', $elementList);
1295 $elementList = array_flip($elementList);
1298 foreach (array_keys($this->_elements
) as $key) {
1299 $name = $this->_elements
[$key]->getName();
1300 if ($this->_freezeAll ||
isset($elementList[$name])) {
1301 $this->_elements
[$key]->freeze();
1302 $this->_elements
[$key]->setPersistantFreeze(false);
1303 unset($elementList[$name]);
1306 $this->_rules
[$name] = array();
1307 // if field is required, remove the rule
1308 $unset = array_search($name, $this->_required
);
1309 if ($unset !== false) {
1310 unset($this->_required
[$unset]);
1315 if (!empty($elementList)) {
1316 return PEAR
::raiseError(null, QUICKFORM_NONEXIST_ELEMENT
, null, E_USER_WARNING
, "Nonexistant element(s): '" . implode("', '", array_keys($elementList)) . "' in HTML_QuickForm::freeze()", 'HTML_QuickForm_Error', true);
1319 } // end func hardFreeze
1326 * A renderer for MoodleQuickForm that only uses XHTML and CSS and no
1327 * table tags, extends PEAR class HTML_QuickForm_Renderer_Tableless
1329 * Stylesheet is part of standard theme and should be automatically included.
1331 * @author Jamie Pratt <me@jamiep.org>
1332 * @license gpl license
1334 class MoodleQuickForm_Renderer
extends HTML_QuickForm_Renderer_Tableless
{
1337 * Element template array
1341 var $_elementTemplates;
1343 * Template used when opening a hidden fieldset
1344 * (i.e. a fieldset that is opened when there is no header element)
1348 var $_openHiddenFieldsetTemplate = "\n\t<fieldset class=\"hidden\">";
1350 * Header Template string
1354 var $_headerTemplate =
1355 "\n\t\t<legend>{header}</legend>\n\t\t<div class=\"advancedbutton\">{advancedimg}{button}</div>\n\t\t";
1358 * Template used when opening a fieldset
1362 var $_openFieldsetTemplate = "\n\t<fieldset class=\"clearfix\" {id}>";
1365 * Template used when closing a fieldset
1369 var $_closeFieldsetTemplate = "\n\t\t</fieldset>";
1372 * Required Note template string
1376 var $_requiredNoteTemplate =
1377 "\n\t\t<div class=\"fdescription required\">{requiredNote}</div>";
1379 var $_advancedElements = array();
1382 * Whether to display advanced elements (on page load)
1384 * @var integer 1 means show 0 means hide
1388 function MoodleQuickForm_Renderer(){
1389 // switch next two lines for ol li containers for form items.
1390 // $this->_elementTemplates=array('default'=>"\n\t\t".'<li class="fitem"><label>{label}{help}<!-- BEGIN required -->{req}<!-- END required --></label><div class="qfelement<!-- BEGIN error --> error<!-- END error --> {type}"><!-- BEGIN error --><span class="error">{error}</span><br /><!-- END error -->{element}</div></li>');
1391 $this->_elementTemplates
= array(
1392 'default'=>"\n\t\t".'<div class="fitem {advanced}<!-- BEGIN required --> required<!-- END required -->"><div class="fitemtitle"><label>{label}<!-- BEGIN required -->{req} <!-- END required -->{advancedimg}</label>{help}</div><div class="felement {type}<!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error">{error}</span><br /><!-- END error -->{element}</div></div>',
1394 'fieldset'=>"\n\t\t".'<div class="fitem {advanced}<!-- BEGIN required --> required<!-- END required -->"><div class="fitemtitle"><div class="fgrouplabel">{label}<!-- BEGIN required -->{req} <!-- END required -->{advancedimg}</div>{help}</div><fieldset class="felement {type}<!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error">{error}</span><br /><!-- END error -->{element}</fieldset></div>',
1396 'static'=>"\n\t\t".'<div class="fitem {advanced}<!-- BEGIN required --> required<!-- END required -->"><div class="fitemtitle"><div class="fstaticlabel">{label}<!-- BEGIN required -->{req} <!-- END required -->{advancedimg}</div>{help}</div><div class="felement {type}<!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error">{error}</span><br /><!-- END error -->{element}</div></div>');
1398 parent
::HTML_QuickForm_Renderer_Tableless();
1401 function setAdvancedElements($elements){
1402 $this->_advancedElements
= $elements;
1406 * What to do when starting the form
1408 * @param MoodleQuickForm $form
1410 function startForm(&$form){
1411 $this->_reqHTML
= $form->getReqHTML();
1412 $this->_elementTemplates
= str_replace('{req}', $this->_reqHTML
, $this->_elementTemplates
);
1413 $this->_advancedHTML
= $form->getAdvancedHTML();
1414 $this->_showAdvanced
= $form->getShowAdvanced();
1415 parent
::startForm($form);
1418 function startGroup(&$group, $required, $error){
1419 if (method_exists($group, 'getElementTemplateType')){
1420 $html = $this->_elementTemplates
[$group->getElementTemplateType()];
1422 $html = $this->_elementTemplates
['default'];
1425 if ($this->_showAdvanced
){
1426 $advclass = ' advanced';
1428 $advclass = ' advanced hide';
1430 if (isset($this->_advancedElements
[$group->getName()])){
1431 $html =str_replace(' {advanced}', $advclass, $html);
1432 $html =str_replace('{advancedimg}', $this->_advancedHTML
, $html);
1434 $html =str_replace(' {advanced}', '', $html);
1435 $html =str_replace('{advancedimg}', '', $html);
1437 if (method_exists($group, 'getHelpButton')){
1438 $html =str_replace('{help}', $group->getHelpButton(), $html);
1440 $html =str_replace('{help}', '', $html);
1442 $html =str_replace('{name}', $group->getName(), $html);
1443 $html =str_replace('{type}', 'fgroup', $html);
1445 $this->_templates
[$group->getName()]=$html;
1446 // Fix for bug in tableless quickforms that didn't allow you to stop a
1447 // fieldset before a group of elements.
1448 // if the element name indicates the end of a fieldset, close the fieldset
1449 if ( in_array($group->getName(), $this->_stopFieldsetElements
)
1450 && $this->_fieldsetsOpen
> 0
1452 $this->_html
.= $this->_closeFieldsetTemplate
;
1453 $this->_fieldsetsOpen
--;
1455 parent
::startGroup($group, $required, $error);
1458 function renderElement(&$element, $required, $error){
1459 //manipulate id of all elements before rendering
1460 if (!is_null($element->getAttribute('id'))) {
1461 $id = $element->getAttribute('id');
1463 $id = $element->getName();
1465 //strip qf_ prefix and replace '[' with '_' and strip ']'
1466 $id = preg_replace(array('/^qf_|\]/', '/\[/'), array('', '_'), $id);
1467 if (strpos($id, 'id_') !== 0){
1468 $element->updateAttributes(array('id'=>'id_'.$id));
1471 //adding stuff to place holders in template
1472 if (method_exists($element, 'getElementTemplateType')){
1473 $html = $this->_elementTemplates
[$element->getElementTemplateType()];
1475 $html = $this->_elementTemplates
['default'];
1477 if ($this->_showAdvanced
){
1478 $advclass = ' advanced';
1480 $advclass = ' advanced hide';
1482 if (isset($this->_advancedElements
[$element->getName()])){
1483 $html =str_replace(' {advanced}', $advclass, $html);
1485 $html =str_replace(' {advanced}', '', $html);
1487 if (isset($this->_advancedElements
[$element->getName()])||
$element->getName() == 'mform_showadvanced'){
1488 $html =str_replace('{advancedimg}', $this->_advancedHTML
, $html);
1490 $html =str_replace('{advancedimg}', '', $html);
1492 $html =str_replace('{type}', 'f'.$element->getType(), $html);
1493 $html =str_replace('{name}', $element->getName(), $html);
1494 if (method_exists($element, 'getHelpButton')){
1495 $html = str_replace('{help}', $element->getHelpButton(), $html);
1497 $html = str_replace('{help}', '', $html);
1501 $this->_templates
[$element->getName()] = $html;
1503 parent
::renderElement($element, $required, $error);
1506 function finishForm(&$form){
1507 parent
::finishForm($form);
1508 // add a lockoptions script
1509 if ('' != ($script = $form->getLockOptionEndScript())) {
1510 $this->_html
= $this->_html
. "\n" . $script;
1514 * Called when visiting a header element
1516 * @param object An HTML_QuickForm_header element being visited
1520 function renderHeader(&$header) {
1521 $name = $header->getName();
1523 $id = empty($name) ?
'' : ' id="' . $name . '"';
1524 $id = preg_replace(array('/\]/', '/\[/'), array('', '_'), $id);
1525 if (is_null($header->_text
)) {
1527 } elseif (!empty($name) && isset($this->_templates
[$name])) {
1528 $header_html = str_replace('{header}', $header->toHtml(), $this->_templates
[$name]);
1530 $header_html = str_replace('{header}', $header->toHtml(), $this->_headerTemplate
);
1533 if (isset($this->_advancedElements
[$name])){
1534 $header_html =str_replace('{advancedimg}', $this->_advancedHTML
, $header_html);
1536 $header_html =str_replace('{advancedimg}', '', $header_html);
1538 $elementName='mform_showadvanced';
1539 if ($this->_showAdvanced
==0){
1540 $buttonlabel = get_string('showadvanced', 'form');
1542 $buttonlabel = get_string('hideadvanced', 'form');
1545 if (isset($this->_advancedElements
[$name])){
1546 $showtext="'".get_string('showadvanced', 'form')."'";
1547 $hidetext="'".get_string('hideadvanced', 'form')."'";
1548 //onclick returns false so if js is on then page is not submitted.
1549 $onclick = 'return showAdvancedOnClick(this, '.$hidetext.', '.$showtext.');';
1550 $button = '<input name="'.$elementName.'" value="'.$buttonlabel.'" type="submit" onclick="'.$onclick.'" />';
1551 $header_html =str_replace('{button}', $button, $header_html);
1553 $header_html =str_replace('{button}', '', $header_html);
1556 if ($this->_fieldsetsOpen
> 0) {
1557 $this->_html
.= $this->_closeFieldsetTemplate
;
1558 $this->_fieldsetsOpen
--;
1561 $openFieldsetTemplate = str_replace('{id}', $id, $this->_openFieldsetTemplate
);
1562 if ($this->_showAdvanced
){
1563 $advclass = ' class="advanced"';
1565 $advclass = ' class="advanced hide"';
1567 if (isset($this->_advancedElements
[$name])){
1568 $openFieldsetTemplate = str_replace('{advancedclass}', $advclass, $openFieldsetTemplate);
1570 $openFieldsetTemplate = str_replace('{advancedclass}', '', $openFieldsetTemplate);
1572 $this->_html
.= $openFieldsetTemplate . $header_html;
1573 $this->_fieldsetsOpen++
;
1574 } // end func renderHeader
1576 function getStopFieldsetElements(){
1577 return $this->_stopFieldsetElements
;
1582 $GLOBALS['_HTML_QuickForm_default_renderer'] =& new MoodleQuickForm_Renderer();
1584 MoodleQuickForm
::registerElementType('checkbox', "$CFG->libdir/form/checkbox.php", 'MoodleQuickForm_checkbox');
1585 MoodleQuickForm
::registerElementType('file', "$CFG->libdir/form/file.php", 'MoodleQuickForm_file');
1586 MoodleQuickForm
::registerElementType('group', "$CFG->libdir/form/group.php", 'MoodleQuickForm_group');
1587 MoodleQuickForm
::registerElementType('password', "$CFG->libdir/form/password.php", 'MoodleQuickForm_password');
1588 MoodleQuickForm
::registerElementType('radio', "$CFG->libdir/form/radio.php", 'MoodleQuickForm_radio');
1589 MoodleQuickForm
::registerElementType('select', "$CFG->libdir/form/select.php", 'MoodleQuickForm_select');
1590 MoodleQuickForm
::registerElementType('text', "$CFG->libdir/form/text.php", 'MoodleQuickForm_text');
1591 MoodleQuickForm
::registerElementType('textarea', "$CFG->libdir/form/textarea.php", 'MoodleQuickForm_textarea');
1592 MoodleQuickForm
::registerElementType('date_selector', "$CFG->libdir/form/dateselector.php", 'MoodleQuickForm_date_selector');
1593 MoodleQuickForm
::registerElementType('date_time_selector', "$CFG->libdir/form/datetimeselector.php", 'MoodleQuickForm_date_time_selector');
1594 MoodleQuickForm
::registerElementType('htmleditor', "$CFG->libdir/form/htmleditor.php", 'MoodleQuickForm_htmleditor');
1595 MoodleQuickForm
::registerElementType('format', "$CFG->libdir/form/format.php", 'MoodleQuickForm_format');
1596 MoodleQuickForm
::registerElementType('static', "$CFG->libdir/form/static.php", 'MoodleQuickForm_static');
1597 MoodleQuickForm
::registerElementType('hidden', "$CFG->libdir/form/hidden.php", 'MoodleQuickForm_hidden');
1598 MoodleQuickForm
::registerElementType('modvisible', "$CFG->libdir/form/modvisible.php", 'MoodleQuickForm_modvisible');
1599 MoodleQuickForm
::registerElementType('modgroupmode', "$CFG->libdir/form/modgroupmode.php", 'MoodleQuickForm_modgroupmode');
1600 MoodleQuickForm
::registerElementType('selectyesno', "$CFG->libdir/form/selectyesno.php", 'MoodleQuickForm_selectyesno');
1601 MoodleQuickForm
::registerElementType('modgrade', "$CFG->libdir/form/modgrade.php", 'MoodleQuickForm_modgrade');
1602 MoodleQuickForm
::registerElementType('cancel', "$CFG->libdir/form/cancel.php", 'MoodleQuickForm_cancel');
1603 MoodleQuickForm
::registerElementType('button', "$CFG->libdir/form/button.php", 'MoodleQuickForm_button');
1604 MoodleQuickForm
::registerElementType('choosecoursefile', "$CFG->libdir/form/choosecoursefile.php", 'MoodleQuickForm_choosecoursefile');
1605 MoodleQuickForm
::registerElementType('header', "$CFG->libdir/form/header.php", 'MoodleQuickForm_header');
1606 MoodleQuickForm
::registerElementType('submit', "$CFG->libdir/form/submit.php", 'MoodleQuickForm_submit');
1607 MoodleQuickForm
::registerElementType('questioncategory', "$CFG->libdir/form/questioncategory.php", 'MoodleQuickForm_questioncategory');
1608 MoodleQuickForm
::registerElementType('advcheckbox', "$CFG->libdir/form/advcheckbox.php", 'MoodleQuickForm_advcheckbox');