QuickHelp
Описание
This document is based on questions asked on PEAR general mailing list. You are encouraged to search the list archives to find more verbose answers and examples.
HTML_QuickForm FAQ
- 1. The forms I generate with HTML_QuickForm cannot be submitted. When I look at the page's HTML source, I see something like <formArray>.
- 2. When I pass some GET parameters to the script containing a form, QuickForm thinks that the form was already submitted, displaying validation errors.
- 3. How do I set default/constant values for 'date' element?
- 4. I receive weird "Call to a member function on a non-object" or "Undefined function" errors, especially when dealing with groups.
- 5. QuickForm generates code which does not validate as XHTML Strict!
- 6. The 'required' rule does not work for my elements!
- 7. How do I change * denotes required field and Invalid information entered. / Please correct these fields. validation messages?
1. The forms I generate with HTML_QuickForm cannot be submitted. When I look at the page's HTML source, I see something like <formArray>.
Recent versions of HTML_QuickForm package require HTML_Common package version 1.2.1 (CVS revision 1.8 in HTML/Common.php) to work properly. If (and only if) an older version of HTML_Common is loaded, these symptoms occur.
Please note that
$ pear list |
2. When I pass some GET parameters to the script containing a form, QuickForm thinks that the form was already submitted, displaying validation errors.
Constructor of HTML_QuickForm accepts a $trackSubmit parameter. Setting this to TRUE will make QuickForm check whether the form was actually submitted. This also helps if you have several forms defined on one page.
Date element is essentially a group of selects, you define the structure of this group in the 'format' option when creating the element:
$form->addElement('date', 'foo', 'The date:', array('format' => 'Y m d')); |
$form->setDefaults(array( 'foo' => array('Y' => 2004, 'm' => 9, 'd' => 29) )); |
To ease using it with database-backed applications, date element also accepts Unix timestamps (generated by mktime()) and strings. The strings are processed by strtotime() functions, so consider its limitations.
4. I receive weird "Call to a member function on a non-object" or "Undefined function" errors, especially when dealing with groups.
These errors tend to appear when you have something which is not a HTML_QuickForm_element in the $elements array passed to addGroup(). This "something" is usually either a PEAR_Error instance (check for these or setup a handler) or, if register_globals is switched on in php.ini, some submitted values (clear the array before adding elements to it).
QuickForm does add a 'name' attribute to the <form> tag, which is invalid in XHTML Strict. Quickform does not depend on that attribute since release 3.2.2, and it's only kept for backwards compatibility. If you desire XHTML Strict compliance and your code does not depend on said attribute, you can remove it via removeAttribute() method.
If your element is a file upload, you should use 'uploadedfile' rule instead.
If your element is a group, you should use addGroupRule() method instead of addRule(). This applies to group-based elements like 'date' and 'hierselect' as well.
7. How do I change * denotes required field and Invalid information entered. / Please correct these fields. validation messages?
You should use setRequiredNote() and setJsWarnings() methods, respectively.
Пред. | Начало | След. |
QuickStart | Уровень выше | QuickForm element types |