Page 494 - Beginning PHP 5.3
P. 494
Part III: Using PHP in Practice
Here are some of the most useful methods of the HTML_QuickForm class:
Method Description
HTML_QuickForm The HTML_QuickForm constructor. All arguments are
( $ formName $ method optional.
,
,
,
,
,
$ action $ target $ attrs
$ formName is the name of the form, included in the < form >
$ trackSubmit )
tag ’ s name attribute. $ method is the form sending method
( “ get ” or “ post “ ; defaults to “ post “ ). $ action is the form ’ s
action attribute — that is, the URL to send the form to.
Leave blank to send the form back to the current script.
$ target is the target attribute, which lets you open the
form handler URL in a new window, for example. $ attrs is
an array of HTML attributes (as name/value pairs) to add to
the opening < form > tag.
Finally, $ trackSubmit if set to true , adds a hidden field
,
to the form to track if it ’ s been submitted or not. It defaults to
false .
addElement() Adds an element to the form, and returns the element object
that was created. The arguments that you need to pass in
depend on the element you ’ re creating. For example, to add a
text input control with a name of “ age ” and a label of “ Your
Age ”, you might write: $form - > addElement( “ text ” ,
)
“ age ”, “ Your Age “ . You can also pass in an HTML_
QuickForm_element object created with createElement() .
createElement() Creates and returns a form element as an HTML_QuickForm_
element object. You can then pass this element to
addElement() to add it to the form, or addGroup() to add it
to a group in the form. The exact arguments to pass in
depend on the type of element you ’ re creating.
addGroup( $ elements , Adds a group of elements to the form. Element groups allow
,
,
$ name $ groupLabel you to treat a bunch of elements much like a single element.
$ separator $ appendName ) They ’ re useful for visually grouping elements in a form, and
,
also for logical grouping (such as creating a group of related
radio buttons).
$ elements is the array of elements to add. $ name is the name
of the group, and $ groupLabel is the label to display next
to the group in the form. $ separator is the markup to use to
separate elements in the group. Set $ appendName to true
to include the group name in each element name in the group
(for example, “ myGroup[myElement] ” instead of just
“ myElement “ ). This setting defaults to false .
All arguments except $ elements are optional.
456
9/21/09 9:14:52 AM
c15.indd 456 9/21/09 9:14:52 AM
c15.indd 456