QuickHelp

QuickHelp – Answers to most Frequently Asked Questions

Description

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

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
              
            

command may tell you that you have HTML_Common 1.2.1 installed. In this case you also have an older version of HTML_Common somewhere and are including it instead of the proper one. Check your include_path setting in php.ini and/or use PHP's get_included_files() function to find out which file you are really including.

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.

How do I set default/constant values for 'date' element?

Date element is essentially a group of selects, you define the structure of this group in the 'format' option when creating the element:

<?php
$form
->addElement('date''foo''The date:', array('format' => 'Y m d'));
?>

Thus you pass the defaults as an array, just like you do with any other group:

<?php
$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.

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 generates code which does not validate as XHTML Strict!

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.

The 'required' rule does not work for my elements!

  • 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.
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.

A tutorial for HTML_QuickForm (Previous) What elements can be added to QuickForm (Next)
Last updated: Fri, 01 Aug 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.