Home » HTML » HTML_QuickForm » Manual
The PEAR::HTML_QuickForm package provides methods for creating, validating and processing HTML forms.
Introduction
QuickForm is a convenience library for dealing with HTML forms.
It provides Javascript and server-side form validation, and is customizable and extensible in many ways.
QuickForm consists of multiple files. The main file is QuickForm.php and should be installed in
your pear/HTML directory. The other important files are element.php,
which handles all methods relative to form elements, and group.php, which deals with
methods relative to groups of elements in the form. Both are located in your HTML/QuickForm
directory along with the other form objects. input.php contains a common class for all
the elements of input type (text, password...). QuickForm has objects for all the common form elements:
select, text, password, checkbox, file, submit, reset, button, image, radio, hidden, textarea.
QuickForm provides the possibility to create your own elements as long as you comply with the common API.
QuickStart
QuickStart – A tutorial for HTML_QuickForm
Introduction
The purpose of this tutorial is to give the new users of QuickForm an overview of its features and usage patterns. It describes a small subset of available functionality, but points to the parts of the documentation that give a more in-depth overview.
There also exists a somewhat bigger tutorial on QuickForm usage made by Keith Edmunds.
Your first form
Basic QuickForm usage
<?php
// Load the main class
require_once 'HTML/QuickForm.php';
// Instantiate the HTML_QuickForm object
$form = new HTML_QuickForm('firstForm');
// Set defaults for the form elements
$form->setDefaults(array(
'name' => 'Joe User'
));
// Add some elements to the form
$form->addElement('header', null, 'QuickForm tutorial example');
$form->addElement('text', 'name', 'Enter your name:', array('size' => 50, 'maxlength' => 255));
$form->addElement('submit', null, 'Send');
// Define filters and validation rules
$form->applyFilter('name', 'trim');
$form->addRule('name', 'Please enter your name', 'required', null, 'client');
// Try to validate a form
if ($form->validate()) {
echo '<h1>Hello, ' . htmlspecialchars($form->exportValue('name')) . '!</h1>';
exit;
}
// Output the form
$form->display();
?>
Lets review this example step by step.
Building the form
The line
<?php
$form = new HTML_QuickForm('firstForm');
?>creates a HTML_QuickForm object that will contain the objects representing elements and all the other
necessary information. We only pass the form's name to the constructor,
which means that default values will be used for other parameters. In particular, the form's method will
default to POST and the form's action to the current file. When using QuickForm, it is
easier to keep all the form related logic in one file.
You might guess that
<?php
$form->setDefaults(array(
'name' => 'Joe User'
));
?>sets the default value for name element to 'Joe User'. QuickForm has the
concept of default values (set via setDefaults() method) and
constant ones (set via setConstants()).
The difference between them is that user's input overrides default values but not constant ones.
Our form will consist of three elements:
<?php
$form->addElement('header', null, 'QuickForm tutorial example');
$form->addElement('text', 'name', 'Enter your name:', array('size' => 50, 'maxlength' => 255));
$form->addElement('submit', null, 'Send');
?>The first one is not the 'real' element, it is just a heading to improve presentation. The second one actually is a text input box and the third is a submit button. Note that parameters for addElement() method have different meanings for different elements. That is so because they are actually passed to these elements' constructors.
Checking input
The line
<?php
$form->applyFilter('name', 'trim');
?>defines a filter for the 'name' element value - the function that will be applied to it after form submit. In this case it is a builtin trim() function, but can be any valid callback. Thus we will strip all whitespace from the name, as we do not actually need it and as we want to be sure that a name was entered, not just some spaces.
Next we define a rule for the name field:
<?php
$form->addRule('name', 'Please enter your name', 'required', null, 'client');
?>This means that QuickForm will display an error message if the name was not entered. The
'client' modifier is here to switch on client-side JavaScript validation in addition to
server-side one. Note also that QuickForm will automatically mark required fields in the form.
Validating and processing
We now have the form built and rules defined and need to decide whether to process it or display:
<?php
if ($form->validate()) {
// Do some stuff
}
?>The validate() method will consider the form valid (i.e. return TRUE) if some data was actually submitted and all the rules defined for the form were satisfied. In our case this means that 'name' element was not empty.
If the form is validated we need to process the values
<?php
echo '<h1>Hello, ' . htmlspecialchars($form->exportValue('name')) . '!</h1>';
exit;
?>This is an example, in your scripts you'll usually want to store the values somewhere and to redirect to some other page to prevent a duplicate submit. The process() and exportvalues() methods may be of interest here.
The last line is pretty easy:
<?php
$form->display();
?>If the form is not valid, which means that it either was not yet submitted or that there were errors, it will be displayed. Error messages (if any) will be displayed near the corresponding elements.
Advanced features
You now should have an understanding of basic QuickForm functionality, but there are many more features in the package, each of them deserving a separate tutorial. This section will give a short overview of them and point you to the complete documentation.
Groups allow to combine several individual elements into one entity and to use it as one element. This is also used to create pseudo-elements like date and hierselect.
QuickForm offers a lot of possibilities to customize form layout and appearance. Form output is done via renderers - special classes containing necessary logic. There are renderers that directly output HTML and those that use template engines for this.
And finally, you can extend QuickForm by adding your own element types, rules and renderers.
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>.
- When I pass some GET parameters to the script containing a form, QuickForm thinks that the form was already submitted, displaying validation errors.
- How do I set default/constant values for 'date' element?
- I receive weird "Call to a member function on a non-object" or "Undefined function" errors, especially when dealing with groups.
- QuickForm generates code which does not validate as XHTML Strict!
- The 'required' rule does not work for my elements!
- How do I change * denotes required field and Invalid information entered. / Please correct these fields. validation messages?
-
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 listcommand 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_pathsetting inphp.iniand/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
$trackSubmitparameter. 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
$elementsarray passed to addGroup(). This "something" is usually either a PEAR_Error instance (check for these or setup a handler) or, ifregister_globalsis switched on inphp.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.
-
If your element is a file upload, you should use
-
How do I change
* denotes required fieldandInvalid information entered. / Please correct these fields.validation messages? -
You should use setRequiredNote() and setJsWarnings() methods, respectively.
QuickForm element types
QuickForm element types – What elements can be added to QuickForm
Elements overview
As of release 3.2.5, HTML_QuickForm knows 23 element types that can be created via createElement() and added to the form via addElement(). These can be divided into two big groups: standard HTML elements and custom elements.
'button'Class for <input type="button" /> elements, HTML_QuickForm_button
'checkbox'Class for <input type="checkbox" /> elements, HTML_QuickForm_checkbox
'file'Class for <input type="file" /> elements, HTML_QuickForm_file
'hidden'Class for <input type="hidden" /> elements, HTML_QuickForm_hidden
'image'Class for <input type="image" /> elements, HTML_QuickForm_image
'password'Class for <input type="password" /> elements, HTML_QuickForm_password
'radio'Class for <input type="radio" /> elements, HTML_QuickForm_radio
'reset'Class for <input type="reset" /> elements, HTML_QuickForm_reset
'select'Class for <select> elements, HTML_QuickForm_select. The class allows loading of <option> elements from array or database.
'submit'Class for <input type="submit" /> elements, HTML_QuickForm_submit
'text'Class for <input type="text" /> elements, HTML_QuickForm_text
'textarea'Class for <textarea> elements, HTML_QuickForm_textarea
'xbutton'Class for <button> elements, HTML_QuickForm_xbutton
'advcheckbox'Class for an advanced checkbox type field, HTML_QuickForm_advcheckbox. Basically this fixes a problem that HTML has had where checkboxes can only pass a single value (the value of the checkbox when checked).
'autocomplete'Class for a text field with autocompletion feature, HTML_QuickForm_autocomplete. The element looks like a normal HTML input text element that at every keypressed javascript event, searches the array of options for a match and autocompletes the text in case of match.
'date'Class for a group of elements used to input dates (and times), HTML_QuickForm_date
'group'Class for a form element group, HTML_QuickForm_group. QuickForm allows grouping of several elements into one entity and using this entity as a new element.
'header'Class for adding headers to the form, HTML_QuickForm_header
'hiddenselect'This class, HTML_QuickForm_hiddenselect, behaves as a select element, but instead of creating a <select> it creates hidden elements for all values already selected with setDefaults() or setConstants().
'hierselect'Class to dynamically create "chained" HTML <select> elements, HTML_QuickForm_hierselect. Choosing an option in the first <select> changes the available options of the second select and so on.
'html'Deprecated. A pseudo-element used for adding raw HTML to form, HTML_QuickForm_html. Intended for use with the default renderer only, template-based ones may (and probably will) completely ignore this.
'link'Class for a link type field, HTML_QuickForm_link
'static'Class for static data, HTML_QuickForm_static
Migration to version 3.2
Migration to version 3.2 – API changes to observe
Why these changes?
HTML_QuickForm has improved a lot since version 2.x. With the addition of a new renderer layer, a lot of methods that were located in the main QuickForm class were actually duplicates of methods in the renderers. Those methods were kept to give user time to adjust their code. With release 3.2 they will be removed, making QuickForm class much lighter and consistent.
At the same time, file upload validation was moved to the file element as this is a more appropriate place.
Removed methods
- QuickForm related
- HTML_QuickForm::getAttributesString()
- HTML_QuickForm::addElementGroup()
- HTML_QuickForm::addHeader()
- HTML_QuickForm::addData()
- Renderer related
- HTML_QuickForm::setElementTemplate()
- HTML_QuickForm::setHeaderTemplate()
- HTML_QuickForm::setFormTemplate()
- HTML_QuickForm::setRequiredNoteTemplate()
- HTML_QuickForm::clearAllTemplates()
- HTML_QuickForm_group::setElementTemplate()
- HTML_QuickForm_group::setGroupTemplate()
- File upload related
- HTML_QuickForm::isUploadedFile()
- HTML_QuickForm::getUploadedFile()
- HTML_QuickForm::moveUploadedFile()
How to adjust your code
QuickForm related
- HTML_QuickForm::getAttributesString()
<?php $form->getAttributes(true); ?>will return the same value by using HTML_Common::getAttributes() method.
- HTML_QuickForm::addElementGroup()
Arguments order was changed to conform to the way elements are usually added to QuickForm by addElement(). Use HTML_QuickForm::addGroup() instead and swap the element label with the element name.
- HTML_QuickForm::addHeader()
A header is now considered like any other element. There is a new HTML_QuickForm_header element that extends HTML_QuickForm_static. Just use
<?php $form->addElement('header', $header_name, $header_text); ?>This will also allow you to customize the header rendering based on its name.
- HTML_QuickForm::addData()
If you absolutely need this feature, use
<?php $form->addElement('html', $data) ?>or consider using some template-based renderer.
Renderer related
Those methods are now handled by the renderers. How to use these methods depends on your choice of renderer. With QuickForm default renderer, you can use these methods like that:
<?php
$form =& new HTML_QuickForm('myform');
$renderer =& $form->defaultRenderer();
$renderer->setFormTemplate('<table><form{attributes}>{content}</form></table>');
$renderer->setHeaderTemplate('<tr><td colspan="2"><b>{header}</b></td></tr>');
$renderer->setGroupTemplate('<table><tr>{content}</tr></table>');
$renderer->setGroupElementTemplate('<td>{element}<br /><!-- BEGIN required -->*<!-- END required -->{label}</td>');
?>
defaultRenderer()will return a reference to QuickForm integrated renderer. You can of course use any other renderer available in QuickForm such as Sigma, ITX, Smarty, Flexy and so on. Have a look at their documentation to see which methods are available for them.
File upload related
File-related methods and rules have been moved to the file element HTML_QuickForm_file because it makes more sense this way and you don't have to include upload-related code if you are not using uploads. You have access to these methods like that:
<?php
$form = new HTML_QuickForm('myform');
$file =& $form->addElement('file', 'myfile', 'Your file:');
$form->addRule('myfile', 'Cannot exceed 1776 bytes', 'maxfilesize', 1776);
if ($file->isUploadedFile()) {
$file->moveUploadedFile('/tmp', 'testfile.txt');
}
?>or like that:
<?php
$file =& $form->getElement('myfile');
if ($file->isUploadedFile()) {
$fileInfo = $file->getValue();
}
?>
Subpackages
Subpackages – An overview about subpackages and packages that use QuickForm
Subpackages for HTML_QuickForm
This section describes the available subpackages for HTML_QuickForm, e.g. custom elements or renderers.
HTML_QuickForm_advmultiselect
A custom element that emulates via two select boxes a select box that allows selecting of multiple options.
HTML_QuickForm_DHTMLRulesTableless
If you use the Tableless renderer (see below, HTML_QuickForm_Renderer_Tableless), this subpackage replaces the default client-side validation with a JavaScript alert window by dynamic (using DHTML) error messages that are printed directly above each erroneous element. (documentation)
HTML_QuickForm_Livesearch
This is another custom element. It creates an HTML input text element that at every keypressed javascript event, returns a list of options in a dynamic dropdown select box (especially useful to emulate a select box with a huge number of options). This element uses the AJAX technology.
HTML_QuickForm_Renderer_Tableless
This is a replacement for the default renderer of HTML_QuickForm that uses only XHTML and CSS but no table tags, and generates fully valid XHTML output. (documentation)
HTML_QuickForm_SelectFilter
Another custom element that is used to define dynamic filters on the client-side for select elements.
More subpackages
There are some more subpackages available that were not yet proposed as PEAR packages. An example is a DHTMLRules subpackage for forms using the default renderer by Justin Patrin that was not yet proposed as a PEAR package.
Packages that use HTML_QuickForm
This section describes some packages that makes working with HTML_QuickForm easier, either in the case of working with databases or in the case of forms that have multiple pages.
DB_DataObject_FormBuilder
FormBuilder aids in rapid application development using the packages DB_DataObject and HTML_QuickForm. (documentation)
DB_Table
This is a package that builds on PEAR DB and MDB2 to abstract datatypes and automate table creation, data validation, insert, update, delete, and select. It combines these with HTML_QuickForm to automatically generate input forms that match the table column definitions. (documentation)
HTML_QuickForm_Controller
If you want to create forms with multiple pages, this is the right package for you. It is an implementation of a PageController pattern. (documentation)
More packages
You can find more packages that have optional or required dependencies on HTML_QuickForm on the package site.
Creating a basic form
To be written.
constructor HTML_QuickForm::HTML_QuickForm()
constructor HTML_QuickForm::HTML_QuickForm() – Class constructor
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::HTML_QuickForm (
string $formName = ''
, string $method = 'post'
, string $action = ''
, string $target = ''
, mixed $attributes
= null
, bool $trackSubmit
= false
)
Description
Constructor, sets <form> tag attributes and loads submitted values.
Parameter
-
string
$formName -
Form's name.
-
string
$method -
(optional) Form's method
-
string
$action -
(optional) Form's action
-
string
$target -
(optional) Form's target
-
mixed
$attributes -
(optional) Extra attributes for <form> tag
-
boolean
$trackSubmit -
(optional) Whether to track if the form was submitted by adding a special hidden field. If the name of such field is not present in the
$_GETor$_POSTvalues, the form will be considered as not submitted.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm::addElement()
HTML_QuickForm::addElement() – Adds an element into the form
Synopsis
require_once 'HTML/QuickForm.php';
object &HTML_QuickForm::addElement (
mixed $element
)
Description
Adds an element into the form. If $element is a string representing an element type, then this method accepts variable number of parameters, their meaning and count depending on element type.
Parameters starting from second will be passed to the element's constructor, consult the docs for the appropriate element to find out which parameters to pass.
Parameter
-
mixed
$element -
element object or type of element to add (text, textarea, file...)
Return value
return reference to added element
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_UNREGISTERED_ELEMENT | Element '$element' does not exist in HTML_QuickForm::_loadElement() |
Tried to add an element of unknown type | Check the type name spelling or use HTML_QuickForm::registerElementType() |
| QUICKFORM_INVALID_ELEMENT_NAME | Element 'elementName' already exists in HTML_QuickForm::addElement() |
Tried to add an element having a name of an existing element, but of different type | Choose a different name for an element |
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::apiVersion()
HTML_QuickForm::apiVersion() – Returns the current API version
Synopsis
require_once 'HTML/QuickForm.php';
float HTML_QuickForm::apiVersion (
void
)
Description
Returns the current API version
Throws
throws no exceptions thrown
Note
since 1.0
This function can be called statically.
HTML_QuickForm::createElement()
HTML_QuickForm::createElement() – Creates a new form element of the given type
Synopsis
require_once 'HTML/QuickForm.php';
object &HTML_QuickForm::createElement (
string $elementType
)
Description
Creates a new form element of the given type. This method accepts variable number of parameters, their meaning and count depending on $elementType.
Parameters starting from second will be passed to the element's constructor, consult the docs for the appropriate element to find out which parameters to pass.
Parameter
-
string
$elementType -
type of element to create (text, textarea, file...)
Return value
return object, descendant of HTML_QuickForm_element
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_UNREGISTERED_ELEMENT | Element '$element' does not exist in HTML_QuickForm::_loadElement() |
Tried to create an element of unknown type | Check the type name spelling or use HTML_QuickForm::registerElementType() |
Note
since 1.0
This function can be called statically.
HTML_QuickForm::elementExists()
HTML_QuickForm::elementExists() – Checks if element is in the form
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::elementExists (
string $element
= null
)
Description
Returns TRUE if element is in the form, FALSE otherwise.
Parameter
-
string
$element -
form name of element to check
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::errorMessage()
HTML_QuickForm::errorMessage() – Returns an error message for error code
Synopsis
require_once 'HTML/QuickForm.php';
string HTML_QuickForm::errorMessage (
int $value
)
Description
Returns a textual error message for QuickForm error code.
Parameter
-
integer
$value -
int error code
Return value
return error message
Throws
throws no exceptions thrown
Note
This function can be called statically.
HTML_QuickForm::getElementType()
HTML_QuickForm::getElementType() – Returns the type of an element
Synopsis
require_once 'HTML/QuickForm.php';
string HTML_QuickForm::getElementType (
string $element
)
Description
Returns the type of the given element.
Parameter
-
string
$element -
Name of form element
Return value
return element type or FALSE if element is not found
Throws
throws no exceptions thrown
Note
since 1.1
This function can not be called statically.
HTML_QuickForm::getElement()
HTML_QuickForm::getElement() – Returns a reference to the element
Synopsis
require_once 'HTML/QuickForm.php';
object &HTML_QuickForm::getElement (
string $element
)
Description
Returns a reference to the form element.
Parameter
-
string
$element -
Element name
Return value
return reference to element
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Element '$element' does not exist in HTML_QuickForm::getElement() |
Tried to get a non-existant element | Check the element's name spelling |
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::getMaxFileSize()
HTML_QuickForm::getMaxFileSize() – Returns the value of MAX_FILE_SIZE hidden element
Synopsis
require_once 'HTML/QuickForm.php';
int HTML_QuickForm::getMaxFileSize (
void
)
Description
Returns the value of MAX_FILE_SIZE hidden element (used for file uploads).
Return value
return max file size in bytes
Throws
throws no exceptions thrown
Note
since 3.0
This function can not be called statically.
HTML_QuickForm::getRegisteredTypes()
HTML_QuickForm::getRegisteredTypes() – Returns registered element types
Synopsis
require_once 'HTML/QuickForm.php';
array HTML_QuickForm::getRegisteredTypes (
void
)
Description
Returns an array of registered element types.
Throws
throws
Note
since 1.0
This function can be called statically.
HTML_QuickForm::insertElementBefore()
HTML_QuickForm::insertElementBefore() – Inserts a new element right before the other element
Synopsis
require_once 'HTML/QuickForm.php';
object &HTML_QuickForm::insertElementBefore (
object &$element
, string $nameAfter
)
Description
Inserts a new element right before the other element.
It is not possible to check whether the $element
is already added to the form, therefore if you want to move the existing form
element to a new position, you'll have to use
removeElement():
<?php
$form->insertElementBefore($form->removeElement('foo', false), 'bar');
?>
Parameter
- object
&$element -
Element to insert (instance of HTML_QuickForm_element)
- string
$nameAfter -
Name of the element before which the new one is inserted
Return value
return reference to inserted element.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_INVALID_ELEMENT_NAME | Several elements named $nameAfter exist in HTML_QuickForm::insertElementBefore() |
Several elements named $nameAfter (e.g.: radios) exist in the form. The method does not handle this case. |
Insert before some other element. Consider adding a dummy element with a unique name. |
| QUICKFORM_INVALID_ELEMENT_NAME | Element '$elementName' already exists in HTML_QuickForm::insertElementBefore() | Element exists with the same name as $element but of different type |
Give some other name to the inserted element. |
| QUICKFORM_NONEXIST_ELEMENT | Element $nameAfter does not exist in HTML_QuickForm::insertElementBefore() |
Tried to insert before a non-existant element | Check the element's name spelling |
Note
since 3.2.4
This function can not be called statically.
HTML_QuickForm::isError()
HTML_QuickForm::isError() – Tells whether a result is an error
Synopsis
require_once 'HTML/QuickForm.php';
bool HTML_QuickForm::isError (
mixed $value
)
Description
Tells whether a result is an error (i.e. whether $value is an instance of HTML_QuickForm_Error).
Parameter
-
mixed
$value -
result of some QuickForm function
Return value
return whether $value is an error
Throws
throws no exceptions thrown
Note
This function can be called statically.
HTML_QuickForm::isTypeRegistered()
HTML_QuickForm::isTypeRegistered() – Checks whether the form element type is supported
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::isTypeRegistered (
string $type
)
Description
Returns whether or not the form element type is supported. New types are added via HTML_QuickForm::registerElementType().
Parameter
-
string
$type -
Form element type
Throws
throws no exceptions thrown
Note
since 1.0
This function can be called statically.
HTML_QuickForm::registerElementType()
HTML_QuickForm::registerElementType() – Registers a new element type
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::registerElementType (
string $typeName
, string $include
, string $className
)
Description
Registers a new element type. After that, elements of this type may be created via createElement() and added to form via addElement().
Parameter
-
string
$typeName -
Name of element type
-
string
$include -
Include path for element type
-
string
$className -
Element class name
Throws
throws no exceptions thrown
Note
since 1.0
This function can be called statically.
HTML_QuickForm::removeElement()
HTML_QuickForm::removeElement() – Removes an element
Synopsis
require_once 'HTML/QuickForm.php';
object &HTML_QuickForm::removeElement (
string $elementName
, boolean $removeRules
= true
)
Description
Removes an element from the form.
Parameter
-
string
$elementName -
The element name
-
boolean
$removeRules -
TRUE if rules for this element are to be removed too
Return value
return reference to element being removed.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Element '$elementName' does not exist in HTML_QuickForm::removeElement() |
Tried to remove a non-existant element | Check the element's name spelling |
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::setMaxFileSize()
HTML_QuickForm::setMaxFileSize() – Sets the value of MAX_FILE_SIZE hidden element
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::setMaxFileSize (
int $bytes
)
Description
Sets the value of MAX_FILE_SIZE hidden element (used for file uploads).
Parameter
-
integer
$bytes -
Size in bytes
Throws
throws no exceptions thrown
Note
since 3.0
This function can not be called statically.
HTML_QuickForm::updateElementAttr()
HTML_QuickForm::updateElementAttr() – Updates Attributes for one or more elements
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::updateElementAttr (
mixed $elements
, mixed $attrs
)
Description
Updates Attributes for one or more elements
This may not work for groups and group-based elements (date, hierselect). To ensure proper behaviour, you should update attributes of grouped elements manually.
Parameter
-
mixed
$elements -
Array of element names/objects or string of elements to be updated
-
mixed
$attrs -
Array or string of html attributes
Throws
throws no exceptions thrown
Note
since 2.10
This function can not be called statically.
Classes representing form elements
To be written
Base classes
Class Summary HTML_QuickForm_element
Class Summary HTML_QuickForm_element – Base class for form elements
Description
This is a base class for all QuickForm elements. It defines the API that is implemented by all the child classes representing actual form elements. You should use these elements, there is no need to directly instantiate HTML_QuickForm_element.
If you would like to create your own element to use with QuickForm, you should extend this class or one of its descendants and make sure to implement all methods defined here. There is also toHtml() method defined in HTML_Common that should be implemented.
Class Trees for HTML_QuickForm_element
-
HTML_Common
- HTML_QuickForm_element
| Class | Summary |
|---|---|
| HTML_QuickForm_group | HTML class for a form element group |
| HTML_QuickForm_input | Base class for input form elements |
| HTML_QuickForm_select | Class to dynamically create an HTML SELECT |
| HTML_QuickForm_static | HTML class for static data |
| HTML_QuickForm_textarea | HTML class for a textarea type field |
constructor HTML_QuickForm_element()
constructor HTML_QuickForm_element() – Class constructor
Synopsis
require_once 'HTML/QuickForm/element.php';
void constructor HTML_QuickForm_element::HTML_QuickForm_element (
string $elementName
= null
, mixed $elementLabel
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Name of the element
-
mixed
$elementLabel -
Label(s) for the element
-
mixed
$attributes -
Associative array of tag attributes or HTML attributes name="value" pairs
Throws
throws no exceptions thrown
See
see setName(), setLabel()
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::accept()
HTML_QuickForm_element::accept() – Accepts a renderer
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::accept (
object HTML_QuickForm_Renderer &$renderer
, bool $required
= false
, string $error
= null
)
Description
This method rarely needs to be called directly, it is usually called from HTML_QuickForm::accept() method.
Parameter
-
object HTML_QuickForm_Renderer
&$renderer -
an instance of HTML_QuickForm_Renderer subclass
-
boolean
$required -
Whether an element is required
-
string
$error -
An error message associated with an element
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_element::apiVersion()
HTML_QuickForm_element::apiVersion() – Returns the current API version
Synopsis
require_once 'HTML/QuickForm/element.php';
float HTML_QuickForm_element::apiVersion (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::exportValue()
HTML_QuickForm_element::exportValue() – Returns a 'safe' element's value (package developer related)
Synopsis
require_once 'HTML/QuickForm/element.php';
mixed HTML_QuickForm_element::exportValue (
array &$submitValues
, bool $assoc
= false
)
Description
This method is not intended to be called directly. It is called by HTML_QuickForm::exportValue() and HTML_QuickForm::exportValues() methods.
The method first tries to find a value for itself in a passed array, if such a value is not found it takes the display value via getValue(). It then filters out the values that cannot possibly be submitted by this element and returns the result.
Parameter
-
array
&$submitValues -
array of submitted values to search
-
boolean
$assoc -
whether to return the value as associative array
Throws
throws no exceptions thrown
See
see getValue(), HTML_QuickForm::exportValue(), HTML_QuickForm::exportValues().
Note
This function can not be called statically.
HTML_QuickForm_element::freeze()
HTML_QuickForm_element::freeze() – Freezes the element
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::freeze (
)
Description
When the element is displayed after the call to freeze(), only its value is displayed without the input tags, thus the element cannot be edited. If persistant freeze is set, then hidden field containing the element value will be output, too.
This method makes sense only with the elements that actually are editable in the first place. It has no effect on buttons, images, hidden fields, static content and the like.
Throws
throws no exceptions thrown
See
see unfreeze(), isFrozen(), setPersistantFreeze(), getFrozenHtml(), HTML_QuickForm::freeze(), HTML_QuickForm::isFrozen().
Note
This function can not be called statically.
Example
Freezing the text element
<?php
require_once 'HTML/QuickForm.php';
$text =& HTML_QuickForm::createElement('text', 'freezeMe');
$text->setValue('Some value');
echo $text->toHtml() . "\n";
$text->freeze();
echo $text->toHtml() . "\n";
$text->setPersistantFreeze(false);
echo $text->toHtml() . "\n";
$text->unfreeze();
echo $text->toHtml() . "\n";
?>
Output
<input name="freezeMe" type="text" value="Some value" />
Some value<input type="hidden" name="freezeMe" value="Some value" />
Some value
<input name="freezeMe" type="text" value="Some value" />
HTML_QuickForm_element::getFrozenHtml()
HTML_QuickForm_element::getFrozenHtml() – Returns the value of field without HTML tags
Synopsis
require_once 'HTML/QuickForm/element.php';
string HTML_QuickForm_element::getFrozenHtml (
)
Description
This method returns the HTML for the element in frozen state. There is rarely a need to call it directly.
Throws
throws no exceptions thrown
See
see isFrozen(), setPersistantFreeze(), freeze().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::getLabel()
HTML_QuickForm_element::getLabel() – Returns the label for the element
Synopsis
require_once 'HTML/QuickForm/element.php';
string HTML_QuickForm_element::getLabel (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see setLabel().
Note
since 1.3
This function can not be called statically.
HTML_QuickForm_element::getName()
HTML_QuickForm_element::getName() – Returns the element name
Synopsis
require_once 'HTML/QuickForm/element.php';
string HTML_QuickForm_element::getName (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see setName().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::getType()
HTML_QuickForm_element::getType() – Returns the element type
Synopsis
require_once 'HTML/QuickForm/element.php';
string HTML_QuickForm_element::getType (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::getValue()
HTML_QuickForm_element::getValue() – Returns the value of the form element
Synopsis
require_once 'HTML/QuickForm/element.php';
mixed HTML_QuickForm_element::getValue (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see setValue(), HTML_QuickForm::getElementValue().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::isFrozen()
HTML_QuickForm_element::isFrozen() – Returns whether or not the element is frozen
Synopsis
require_once 'HTML/QuickForm/element.php';
bool HTML_QuickForm_element::isFrozen (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see freeze().
Note
since 1.3
This function can not be called statically.
HTML_QuickForm_element::onQuickFormEvent()
HTML_QuickForm_element::onQuickFormEvent() – Called by HTML_QuickForm whenever form event is made on this element (package developer related)
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::onQuickFormEvent (
string $event
, mixed $arg
, object &$caller
)
Description
This method is not intended to be called directly.
If you are creating your own element, you should override this method and create handlers for each of available QuickForm events.
'addElement'This event is sent by HTML_QuickForm::addElement() method when adding a new element to the form. Its handler should usually send
'createElement'and'updateValue'events.
'createElement'This event is sent by HTML_QuickForm::createElement() method after the element object is instantiated. Its handler should usually call class constructor using the contents of
$argas parameters.
'setGroupValue'The event is sent by HTML_QuickForm_group::setValue() method to each of the grouped elements. The handler generally should set the element's value to
$arg.
'updateValue'The event is sent by QuickForm when the element is added to the form and when form default and constant values are set. The handler for this event is the most complex one: it should search for element's value within form's constant, submit (if applicable) and default values (in that order) and set the element's value to the found one.
Parameter
-
string
$event -
Name of event
-
mixed
$arg -
event arguments
-
object
&$caller -
calling object
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::setLabel()
HTML_QuickForm_element::setLabel() – Sets a label for the element
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::setLabel (
mixed $label
)
Description
Label is a description text that will be displayed near the element. Some renderers can handle multiple labels for the element.
Parameter
-
mixed
$label -
Display text for the element
Throws
throws no exceptions thrown
See
see getLabel().
Note
since 1.3
This function can not be called statically.
HTML_QuickForm_element::setName()
HTML_QuickForm_element::setName() – Sets the input field name
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::setName (
string $name
)
Description
This package is not documented yet.
Parameter
-
string
$name -
Input field name attribute
Throws
throws no exceptions thrown
See
see getName().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::setPersistantFreeze()
HTML_QuickForm_element::setPersistantFreeze() – Sets whether element value should persist on freeze()
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::setPersistantFreeze (
bool $persistant
= false
)
Description
Sets whether an element value should be kept in an hidden field when the element is frozen or not.
Parameter
-
boolean
$persistant -
True if persistant value
Throws
throws no exceptions thrown
See
see freeze(), getFrozenHtml().
Note
since 2.0
This function can not be called statically.
HTML_QuickForm_element::setValue()
HTML_QuickForm_element::setValue() – Sets the value of the form element
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::setValue (
mixed $value
)
Description
This sets the display value for the element. It can be different from its submit value.
Parameter
-
mixed
$value -
Default value of the form element
Throws
throws no exceptions thrown
See
see getValue().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_element::unfreeze()
HTML_QuickForm_element::unfreeze() – Unfreezes the element
Synopsis
require_once 'HTML/QuickForm/element.php';
void HTML_QuickForm_element::unfreeze (
)
Description
Unfreezes the element so that it becomes editable again.
Throws
throws no exceptions thrown
See
see freeze(), isFrozen(), setPersistantFreeze(), getFrozenHtml(), HTML_QuickForm::freeze(), HTML_QuickForm::isFrozen().
Note
This function can not be called statically.
Class Summary HTML_QuickForm_input
Class Summary HTML_QuickForm_input – Base class for input form elements
Description
Since <input> elements have very similar HTML representations, they have this common base class. You don't need to instantiate it directly, use one of the child classes.
Class Trees for HTML_QuickForm_input
-
HTML_Common
-
HTML_QuickForm_element
- HTML_QuickForm_input
-
HTML_QuickForm_element
| Class | Summary |
|---|---|
| HTML_QuickForm_button | HTML class for a button type element |
| HTML_QuickForm_checkbox | HTML class for a checkbox type field |
| HTML_QuickForm_file | HTML class for a file type element |
| HTML_QuickForm_hidden | HTML class for a hidden type element |
| HTML_QuickForm_image | HTML class for a image type element |
| HTML_QuickForm_password | HTML class for a password type field |
| HTML_QuickForm_radio | HTML class for a radio type element |
| HTML_QuickForm_reset | HTML class for a reset type element |
| HTML_QuickForm_submit | HTML class for a submit type element |
| HTML_QuickForm_text | HTML class for a text field |
HTML_QuickForm_input Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_input()
constructor HTML_QuickForm_input() – Class constructor
Synopsis
require_once 'HTML/QuickForm/input.php';
void constructor HTML_QuickForm_input::HTML_QuickForm_input (
string $elementName
= null
, mixed $elementLabel
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Input field name attribute
-
mixed
$elementLabel -
Label(s) for the input field
-
mixed
$attributes -
Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_input::setType()
HTML_QuickForm_input::setType() – Sets the element type
Synopsis
require_once 'HTML/QuickForm/input.php';
void HTML_QuickForm_input::setType (
string $type
)
Description
This package is not documented yet.
Parameter
-
string
$type -
Element type
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
Standard HTML elements
Class Summary HTML_QuickForm_checkbox
Class Summary HTML_QuickForm_checkbox – HTML class for a checkbox type field
Description
This package is not documented yet.
Class Trees for HTML_QuickForm_checkbox
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_checkbox
-
HTML_QuickForm_input
-
HTML_QuickForm_element
| Class | Summary |
|---|---|
| HTML_QuickForm_advcheckbox | HTML class for an advanced checkbox type field |
HTML_QuickForm_checkbox Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_checkbox()
constructor HTML_QuickForm_checkbox() – Class constructor
Synopsis
require_once 'HTML/QuickForm/checkbox.php';
void constructor HTML_QuickForm_checkbox::HTML_QuickForm_checkbox (
string $elementName
= null
, string $elementLabel
= null
, string $text = ''
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Input field name attribute
-
string
$elementLabel -
(optional)Input field label
-
string
$text -
(optional)Checkbox display text
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_checkbox::getChecked()
HTML_QuickForm_checkbox::getChecked() – Returns whether a checkbox is checked
Synopsis
require_once 'HTML/QuickForm/checkbox.php';
bool HTML_QuickForm_checkbox::getChecked (
)
Description
Returns TRUE if checkbox has a "checked" attribute, FALSE otherwise. getValue() is an alias for this method. Thus the only value checkbox element can have in QuickForm is TRUE.
Throws
throws no exceptions thrown
See
see setChecked().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_checkbox::getText()
HTML_QuickForm_checkbox::getText() – Returns the checkbox text
Synopsis
require_once 'HTML/QuickForm/checkbox.php';
string HTML_QuickForm_checkbox::getText (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see setText().
Note
since 1.1
This function can not be called statically.
HTML_QuickForm_checkbox::setChecked()
HTML_QuickForm_checkbox::setChecked() – Sets whether a checkbox is checked
Synopsis
require_once 'HTML/QuickForm/checkbox.php';
void HTML_QuickForm_checkbox::setChecked (
bool $checked
)
Description
This sets or removes the element's "checked" attribute based on $checked value. setValue() is an alias for this method.
Parameter
-
boolean
$checked -
Whether the field is checked or not
Throws
throws no exceptions thrown
See
see getChecked().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_checkbox::setText()
HTML_QuickForm_checkbox::setText() – Sets the checkbox text
Synopsis
require_once 'HTML/QuickForm/checkbox.php';
void HTML_QuickForm_checkbox::setText (
string $text
)
Description
This means the text that would be displayed with the checkbox, automatically enclosed in <label> tags. The label in QuickForm's sense is set via setLabel().
Parameter
-
string
$text
Throws
throws no exceptions thrown
See
see getText().
Note
since 1.1
This function can not be called statically.
Class Summary HTML_QuickForm_file
Class Summary HTML_QuickForm_file – HTML class for a file type element
Description
Alongside the usual element's methods, the class has special methods for working with uploaded files. When the class is included it also registers rules for validating the uploaded files.
Class Trees for HTML_QuickForm_file
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_file
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_file Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_file()
constructor HTML_QuickForm_file() – Class constructor
Synopsis
require_once 'HTML/QuickForm/file.php';
void constructor HTML_QuickForm_file::HTML_QuickForm_file (
string $elementName
= null
, string $elementLabel
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Input field name attribute
-
string
$elementLabel -
Input field label
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_file::getSize()
HTML_QuickForm_file::getSize() – Returns size of file element
Synopsis
require_once 'HTML/QuickForm/file.php';
int HTML_QuickForm_file::getSize (
)
Description
This means 'size' attribute of the <input /> element, not size of the uploaded file.
Throws
throws no exceptions thrown
See
see setSize().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_file::getValue()
HTML_QuickForm_file::getValue() – Returns information about the uploaded file
Synopsis
require_once 'HTML/QuickForm/file.php';
array HTML_QuickForm_file::getValue (
)
Description
Returns the information about the file upload, as in the $_FILES array. Note that while there exists a setValue() method, the method does nothing at all. The file element does not have a value if the form was not submitted.
Throws
throws no exceptions thrown
Note
since 3.0
This function can not be called statically.
HTML_QuickForm_file::isUploadedFile()
HTML_QuickForm_file::isUploadedFile() – Checks if the element contains an uploaded file
Synopsis
require_once 'HTML/QuickForm/file.php';
bool HTML_QuickForm_file::isUploadedFile (
)
Description
This package is not documented yet.
Return value
returns true if file has been uploaded, false otherwise
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_file::moveUploadedFile()
HTML_QuickForm_file::moveUploadedFile() – Moves an uploaded file into the destination
Synopsis
require_once 'HTML/QuickForm/file.php';
bool HTML_QuickForm_file::moveUploadedFile (
string $dest
, string $fileName = ''
)
Description
This package is not documented yet.
Parameter
-
string
$dest -
Destination directory path
-
string
$fileName -
New file name (if not given, original file name will be used).
Return value
returns true if file has been moved successfully, false otherwise.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_file::setSize()
HTML_QuickForm_file::setSize() – Sets size of file element
Synopsis
require_once 'HTML/QuickForm/file.php';
void HTML_QuickForm_file::setSize (
int $size
)
Description
This package is not documented yet.
Parameter
-
integer
$size -
Size of file element
Throws
throws no exceptions thrown
See
see getSize().
Note
since 1.0
This function can not be called statically.
Class Summary HTML_QuickForm_image
Class Summary HTML_QuickForm_image – HTML class for a image type element
Description
This package is not documented yet.
Class Trees for HTML_QuickForm_image
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_image
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_image Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_image()
constructor HTML_QuickForm_image() – Class constructor
Synopsis
require_once 'HTML/QuickForm/image.php';
void constructor HTML_QuickForm_image::HTML_QuickForm_image (
string $elementName
= null
, string $src = ''
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Element name attribute
-
string
$src -
(optional)Image source
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_image::setAlign()
HTML_QuickForm_image::setAlign() – Sets alignment for image element
Synopsis
require_once 'HTML/QuickForm/image.php';
void HTML_QuickForm_image::setAlign (
string $align
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('align' => $align));
?>
Parameter
-
string
$align -
alignment for image element
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_image::setBorder()
HTML_QuickForm_image::setBorder() – Sets border size for image element
Synopsis
require_once 'HTML/QuickForm/image.php';
void HTML_QuickForm_image::setBorder (
string $border
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('border' => $border));
?>
Parameter
-
string
$border -
border for image element
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_image::setSource()
HTML_QuickForm_image::setSource() – Sets source for image element
Synopsis
require_once 'HTML/QuickForm/image.php';
void HTML_QuickForm_image::setSource (
string $src
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('src' => $src));
?>
Parameter
-
string
$src -
source for image element
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
Class Summary HTML_QuickForm_password
Class Summary HTML_QuickForm_password – HTML class for a password type field
Description
This package is not documented yet.
Class Trees for HTML_QuickForm_password
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_password
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_password Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_password()
constructor HTML_QuickForm_password() – Class constructor
Synopsis
require_once 'HTML/QuickForm/password.php';
void constructor HTML_QuickForm_password::HTML_QuickForm_password (
string $elementName
= null
, string $elementLabel
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Input field name attribute
-
string
$elementLabel -
(optional)Input field label
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_password::setMaxlength()
HTML_QuickForm_password::setMaxlength() – Sets maxlength of password element
Synopsis
require_once 'HTML/QuickForm/password.php';
void HTML_QuickForm_password::setMaxlength (
string $maxlength
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('maxlength' => $maxlength));
?>
Parameter
-
string
$maxlength -
Maximum length of password field
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_password::setSize()
HTML_QuickForm_password::setSize() – Sets size of password element
Synopsis
require_once 'HTML/QuickForm/password.php';
void HTML_QuickForm_password::setSize (
string $size
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('size' => $size));
?>
Parameter
-
string
$size -
Size of password field
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
Class Summary HTML_QuickForm_radio
Class Summary HTML_QuickForm_radio – HTML class for a radio type element
Description
This package is not documented yet.
Class Trees for HTML_QuickForm_radio
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_radio
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_radio Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_radio()
constructor HTML_QuickForm_radio() – Class constructor
Synopsis
require_once 'HTML/QuickForm/radio.php';
void constructor HTML_QuickForm_radio::HTML_QuickForm_radio (
string $elementName
= null
, mixed $elementLabel
= null
, string $text
= null
, string $value
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Input field name attribute
-
mixed
$elementLabel -
Label(s) for a field
-
string
$text -
Text to display near the radio
-
string
$value -
Input field value
-
mixed
$attributes -
Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_radio::getChecked()
HTML_QuickForm_radio::getChecked() – Returns whether radio button is checked
Synopsis
require_once 'HTML/QuickForm/radio.php';
string HTML_QuickForm_radio::getChecked (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see setChecked().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_radio::getText()
HTML_QuickForm_radio::getText() – Returns the radio text
Synopsis
require_once 'HTML/QuickForm/radio.php';
string HTML_QuickForm_radio::getText (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see setText().
Note
since 1.1
This function can not be called statically.
HTML_QuickForm_radio::setChecked()
HTML_QuickForm_radio::setChecked() – Sets whether radio button is checked
Synopsis
require_once 'HTML/QuickForm/radio.php';
void HTML_QuickForm_radio::setChecked (
bool $checked
)
Description
This package is not documented yet.
Parameter
-
boolean
$checked -
Whether the field is checked or not
Throws
throws no exceptions thrown
See
see getChecked().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_radio::setText()
HTML_QuickForm_radio::setText() – Sets the radio text
Synopsis
require_once 'HTML/QuickForm/radio.php';
void HTML_QuickForm_radio::setText (
string $text
)
Description
This means the text that would be displayed with the radio, automatically enclosed in <label> tags. The label in QuickForm's sense is set via setLabel().
Parameter
-
string
$text -
Text to display near the radio button
Throws
throws no exceptions thrown
See
see getText().
Note
since 1.1
This function can not be called statically.
Class Summary HTML_QuickForm_reset
Class Summary HTML_QuickForm_reset – HTML class for a reset type element
Description
This package is not documented yet.
Class Trees for HTML_QuickForm_reset
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_reset
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_reset Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_reset()
constructor HTML_QuickForm_reset() – Class constructor
Synopsis
require_once 'HTML/QuickForm/reset.php';
void constructor HTML_QuickForm_reset::HTML_QuickForm_reset (
string $elementName
= null
, string $value
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Input field name attribute
-
string
$value -
(optional)Input field value
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
Class Summary HTML_QuickForm_select
Class Summary HTML_QuickForm_select – Class to dynamically create an HTML SELECT
Description
The highlight of this class is that it allows populating the options from associative array or from the database.
Class Trees for HTML_QuickForm_select
-
HTML_Common
-
HTML_QuickForm_element
- HTML_QuickForm_select
-
HTML_QuickForm_element
| Class | Summary |
|---|---|
| HTML_QuickForm_hiddenselect | Creates hidden elements with select's values |
HTML_QuickForm_select Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_select()
constructor HTML_QuickForm_select() – Class constructor
Synopsis
require_once 'HTML/QuickForm/select.php';
void constructor HTML_QuickForm_select::HTML_QuickForm_select (
string $elementName
= null
, mixed $elementLabel
= null
, mixed $options
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Select name attribute
-
mixed
$elementLabel -
Label(s) for the select
-
mixed
$options -
Data to be used to populate options
-
mixed
$attributes -
Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
See
see load().
Note
since 1.0
This function can not be called statically.
Example
<?php
$select = $quickform->createElement(
'select', 'selectname',
'Label for select',
array('fr' => 'French', 'de' => 'German', 'en_GB' => 'British English'),
array('id' => 'selectname', 'onchange' => '...'));
);
?>
HTML_QuickForm_select::addOption()
HTML_QuickForm_select::addOption() – Adds a new OPTION to the SELECT
Synopsis
require_once 'HTML/QuickForm/select.php';
void HTML_QuickForm_select::addOption (
string $text
, string $value
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$text -
Display text for the OPTION
-
string
$value -
Value for the OPTION
-
mixed
$attributes -
Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_select::getMultiple()
HTML_QuickForm_select::getMultiple() – Returns the select mutiple attribute
Synopsis
require_once 'HTML/QuickForm/select.php';
bool HTML_QuickForm_select::getMultiple (
)
Description
This method returns TRUE if a multiple attribute is present in the select, FALSE otherwise.
Return value
returns true if multiple select, false otherwise
Throws
throws no exceptions thrown
See
see setMultiple().
Note
since 1.2
This function can not be called statically.
HTML_QuickForm_select::getPrivateName()
HTML_QuickForm_select::getPrivateName() – Returns the element name (possibly with brackets appended)
Synopsis
require_once 'HTML/QuickForm/select.php';
string HTML_QuickForm_select::getPrivateName (
)
Description
If select has a multiple attribute present, then this method returns the name with brackets appended, else the result is identical to getName().
Throws
throws no exceptions thrown
See
see getName(), getMultiple().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_select::getSelected()
HTML_QuickForm_select::getSelected() – Returns an array of the selected values
Synopsis
require_once 'HTML/QuickForm/select.php';
array HTML_QuickForm_select::getSelected (
)
Description
This function is an alias to getValue().
Return value
returns of selected values
Throws
throws no exceptions thrown
See
see getValue(), setSelected().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_select::getSize()
HTML_QuickForm_select::getSize() – Returns the select field size
Synopsis
require_once 'HTML/QuickForm/select.php';
int HTML_QuickForm_select::getSize (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
See
see setSize().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_select::load()
HTML_QuickForm_select::load() – Loads options from different types of data sources
Synopsis
require_once 'HTML/QuickForm/select.php';
PEAR_Error HTML_QuickForm_select::load (
mixed &$options
, mixed $param1
= null
, mixed $param2
= null
, mixed $param3
= null
, mixed $param4
= null
)
Description
This method is a simulated overloaded method. The arguments, other than the first are optional and only mean something depending on the type of the first argument.
If the first argument is an array then all arguments are passed in order to loadArray(). If the first argument is a DB_Result then all arguments are passed in order to loadDbResult(). If the first argument is a string or a DB connection then all arguments are passed in order to loadQuery().
Parameter
-
mixed
&$options -
Options source currently supports assoc array or DB_result
-
mixed
$param1 -
(optional) See function detail
-
mixed
$param2 -
(optional) See function detail
-
mixed
$param3 -
(optional) See function detail
-
mixed
$param4 -
(optional) See function detail
Return value
returns TRUE on success
Throws
throws PEAR_Error
See
see loadArray(), loadDbResult(), loadQuery().
Note
since 1.1
This function can not be called statically.
HTML_QuickForm_select::loadArray()
HTML_QuickForm_select::loadArray() – Loads the options from an associative array
Synopsis
require_once 'HTML/QuickForm/select.php';
mixed HTML_QuickForm_select::loadArray (
array $arr
, mixed $values
= null
)
Description
The array should have the form 'option value' => 'option text'.
Parameter
-
array
$arr -
Associative array of options
-
mixed
$values -
(optional) Array or comma delimited string of selected values
Return value
returns TRUE on success
Throws
throws PEAR_Error
See
see load(), addOption().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_select::loadDbResult()
HTML_QuickForm_select::loadDbResult() – Loads the options from DB_result object
Synopsis
require_once 'HTML/QuickForm/select.php';
mixed HTML_QuickForm_select::loadDbResult (
object DB_Result &$result
, string $textCol
= null
, string $valueCol
= null
, mixed $values
= null
)
Description
If no column names are specified the first two columns of the result are used as the text and value columns respectively.
Parameter
-
object
&$result -
DB_result object
-
string
$textCol -
(optional) Name of column to display as the OPTION text
-
string
$valueCol -
(optional) Name of column to use as the OPTION value
-
mixed
$values -
(optional) Array or comma delimited string of selected values
Return value
returns TRUE on success or PEAR_Error
Throws
throws PEAR_Error
See
see load(), addOption().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_select::loadQuery()
HTML_QuickForm_select::loadQuery() – Queries a database and loads the options from the results
Synopsis
require_once 'HTML/QuickForm/select.php';
mixed HTML_QuickForm_select::loadQuery (
mixed &$conn
, string $sql
, string $textCol
= null
, string $valueCol
= null
, mixed $values
= null
)
Description
If no column names are specified the first two columns of the result are used as the text and value columns respectively.
Parameter
-
mixed
&$conn -
Either an existing DB connection or a valid dsn
-
string
$sql -
SQL query string
-
string
$textCol -
(optional) Name of column to display as the OPTION text
-
string
$valueCol -
(optional) Name of column to use as the OPTION value
-
mixed
$values -
(optional) Array or comma delimited string of selected values
Throws
throws PEAR_Error
See
see load(), loadDbResult(), addOption().
Note
since 1.1
This function can not be called statically.
HTML_QuickForm_select::setMultiple()
HTML_QuickForm_select::setMultiple() – Sets the select mutiple attribute
Synopsis
require_once 'HTML/QuickForm/select.php';
void HTML_QuickForm_select::setMultiple (
bool $multiple
)
Description
This method just adds or removes the multiple attribute of select depending on $multiple value.
Parameter
-
boolean
$multiple -
Whether the select supports multi-selections
Throws
throws no exceptions thrown
See
see getMultiple().
Note
since 1.2
This function can not be called statically.
HTML_QuickForm_select::setSelected()
HTML_QuickForm_select::setSelected() – Sets the default values of the select box
Synopsis
require_once 'HTML/QuickForm/select.php';
void HTML_QuickForm_select::setSelected (
mixed $values
)
Description
This method is an alias for setValue(). For multiple selects you can pass either an array or a comma delimited string of values.
Parameter
-
mixed
$values -
Array or comma delimited string of selected values
Throws
throws no exceptions thrown
See
see getSelected().
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_select::setSize()
HTML_QuickForm_select::setSize() – Sets the select field size, only applies to 'multiple' selects
Synopsis
require_once 'HTML/QuickForm/select.php';
void HTML_QuickForm_select::setSize (
int $size
)
Description
This package is not documented yet.
Parameter
-
integer
$size -
Size of select field
Throws
throws no exceptions thrown
See
see getSize().
Note
since 1.0
This function can not be called statically.
Class Summary HTML_QuickForm_submit
Class Summary HTML_QuickForm_submit – HTML class for a submit type element
Description
This package is not documented yet.
Class Trees for HTML_QuickForm_submit
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_submit
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_submit Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_submit()
constructor HTML_QuickForm_submit() – Class constructor
Synopsis
require_once 'HTML/QuickForm/submit.php';
void constructor HTML_QuickForm_submit::HTML_QuickForm_submit (
string $elementName
= null
, string $value
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Input field name attribute
-
string
$value -
Input field value
-
mixed
$attributes -
Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
Class Summary HTML_QuickForm_text
Class Summary HTML_QuickForm_text – HTML class for a text field
Description
This package is not documented yet.
Class Trees for HTML_QuickForm_text
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
- HTML_QuickForm_text
-
HTML_QuickForm_input
-
HTML_QuickForm_element
| Class | Summary |
|---|---|
| HTML_QuickForm_autocomplete | HTML class for a text field with autocompletion feature |
HTML_QuickForm_text Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_text
constructor HTML_QuickForm_text – Class constructor
Synopsis
require_once 'HTML/QuickForm/text.php';
void constructor HTML_QuickForm_text::HTML_QuickForm_text (
string $elementName
= null
, string $elementLabel
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Input field name attribute
-
string
$elementLabel -
(optional)Input field label
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_text::setMaxlength()
HTML_QuickForm_text::setMaxlength() – Sets maxlength of text field
Synopsis
require_once 'HTML/QuickForm/text.php';
void HTML_QuickForm_text::setMaxlength (
string $maxlength
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('maxlength' => $maxlength));
?>
Parameter
-
string
$maxlength -
Maximum length of text field
Throws
throws no exceptions thrown
Note
since 1.3
This function can not be called statically.
HTML_QuickForm_text::setSize()
HTML_QuickForm_text::setSize() – Sets size of text field
Synopsis
require_once 'HTML/QuickForm/text.php';
void HTML_QuickForm_text::setSize (
string $size
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('size' => $size));
?>
Parameter
-
string
$size -
Size of text field
Throws
throws no exceptions thrown
Note
since 1.3
This function can not be called statically.
Class Summary HTML_QuickForm_textarea
Class Summary HTML_QuickForm_textarea – HTML class for a textarea type field
HTML class for a textarea type field
This package is not documented yet.
Class Trees for HTML_QuickForm_textarea
-
HTML_Common
-
HTML_QuickForm_element
- HTML_QuickForm_textarea
-
HTML_QuickForm_element
HTML_QuickForm_textarea Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_textarea()
constructor HTML_QuickForm_textarea() – Class constructor
Synopsis
require_once 'HTML/QuickForm/textarea.php';
void constructor HTML_QuickForm_textarea::HTML_QuickForm_textarea (
string $elementName
= null
, mixed $elementLabel
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Input field name attribute
-
mixed
$elementLabel -
Label(s) for a field
-
mixed
$attributes -
Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_textarea::setCols()
HTML_QuickForm_textarea::setCols() – Sets width in cols for textarea element
Synopsis
require_once 'HTML/QuickForm/textarea.php';
void HTML_QuickForm_textarea::setCols (
string $cols
)
Description
This package is not documented yet.
Parameter
-
string
$cols -
Width expressed in cols
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_textarea::setRows()
HTML_QuickForm_textarea::setRows() – Sets height in rows for textarea element
Synopsis
require_once 'HTML/QuickForm/textarea.php';
void HTML_QuickForm_textarea::setRows (
string $rows
)
Description
This package is not documented yet.
Parameter
-
string
$rows -
Height expressed in rows
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_textarea::setWrap()
HTML_QuickForm_textarea::setWrap() – Sets wrap type for textarea element
Synopsis
require_once 'HTML/QuickForm/textarea.php';
void HTML_QuickForm_textarea::setWrap (
string $wrap
)
Description
This package is not documented yet.
Parameter
-
string
$wrap -
Wrap type
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
Custom elements
Class Summary HTML_QuickForm_advcheckbox
Class Summary HTML_QuickForm_advcheckbox – HTML class for an advanced checkbox type field
Description
HTML class for an advanced checkbox type field. Basically this fixes a problem that HTML has had where checkboxes can only pass a single value (the value of the checkbox when checked). A value for when the checkbox is not checked cannot be passed, and furthermore the checkbox variable doesn't even exist if the checkbox was submitted unchecked.
It works by creating a hidden field with the passed-in name and creating the checkbox with no name, but with a javascript onclick which sets the value of the hidden field.
Class Trees for HTML_QuickForm_advcheckbox
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
-
HTML_QuickForm_checkbox
- HTML_QuickForm_advcheckbox
-
HTML_QuickForm_checkbox
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_advcheckbox Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_checkbox::HTML_QuickForm_checkbox() | Class constructor |
| HTML_QuickForm_checkbox::exportValue() | Return true if the checkbox is checked, null if it is not checked (getValue() returns false) |
| HTML_QuickForm_checkbox::getChecked() | Returns whether a checkbox is checked |
| HTML_QuickForm_checkbox::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_checkbox::getText() | Returns the checkbox text |
| HTML_QuickForm_checkbox::getValue() | Returns the value of the form element |
| HTML_QuickForm_checkbox::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_checkbox::setChecked() | Sets whether a checkbox is checked |
| HTML_QuickForm_checkbox::setText() | Sets the checkbox text |
| HTML_QuickForm_checkbox::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_advcheckbox()
constructor HTML_QuickForm_advcheckbox() – Class constructor
Synopsis
require_once 'HTML/QuickForm/advcheckbox.php';
void constructor HTML_QuickForm_advcheckbox::HTML_QuickForm_advcheckbox (
string $elementName
= null
, string $elementLabel
= null
, string $text
= null
, mixed $attributes
= null
, mixed $values
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Input field name attribute
-
string
$elementLabel -
(optional)Input field label
-
string
$text -
(optional)Text to put after the checkbox
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
-
mixed
$values -
(optional)Values to pass if checked or not checked
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_advcheckbox::getOnclickJs()
HTML_QuickForm_advcheckbox::getOnclickJs() – Create the javascript for the onclick event
Synopsis
require_once 'HTML/QuickForm/advcheckbox.php';
string HTML_QuickForm_advcheckbox::getOnclickJs (
string $elementName
)
Description
Create the javascript for the onclick event which will set the value of the hidden field.
Parameter
-
string
$elementName -
The element name
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_advcheckbox::getPrivateName()
HTML_QuickForm_advcheckbox::getPrivateName() – Gets the private name for the element
Synopsis
require_once 'HTML/QuickForm/advcheckbox.php';
string HTML_QuickForm_advcheckbox::getPrivateName (
string $elementName
)
Description
This is the name that will be used by the actual checkbox.
Parameter
-
string
$elementName -
The element name to make private
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_advcheckbox::setValues()
HTML_QuickForm_advcheckbox::setValues() – Sets the values used by the hidden element
Synopsis
require_once 'HTML/QuickForm/advcheckbox.php';
void HTML_QuickForm_advcheckbox::setValues (
mixed $values
)
Description
If $values is a string then it will be used for checked state. If it is an array, then $values[0] will be used for unchecked state and $values[1] for checked.
Parameter
-
mixed
$values -
The values, either a string or an array
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Class Summary HTML_QuickForm_autocomplete
Class Summary HTML_QuickForm_autocomplete – HTML class for a text field with autocompletion feature
Description
The element looks like a normal HTML input text element that at every keypressed javascript event searches the array of options for a match and autocompletes the text in case of match. This is similar to the browsers' behaviour when one enters the URL into the Address field.
Class Trees for HTML_QuickForm_autocomplete
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_input
-
HTML_QuickForm_text
- HTML_QuickForm_text
-
HTML_QuickForm_text
-
HTML_QuickForm_input
-
HTML_QuickForm_element
HTML_QuickForm_autocomplete Inherited Methods
| Method Name | Summary |
|---|---|
| HTML_QuickForm_text::HTML_QuickForm_text() | Class constructor |
| HTML_QuickForm_text::setMaxLength() | Sets maxlength of text field |
| HTML_QuickForm_text::setSize() | Sets size of text field |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_input::HTML_QuickForm_input() | Class constructor |
| HTML_QuickForm_input::exportValue() | We don't need values from button-type elements (except submit) and files |
| HTML_QuickForm_input::getName() | Returns the element name |
| HTML_QuickForm_input::getValue() | Returns the value of the form element |
| HTML_QuickForm_input::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_input::setName() | Sets the input field name |
| HTML_QuickForm_input::setType() | Sets the element type |
| HTML_QuickForm_input::setValue() | Sets the value of the form element |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_autocomplete
constructor HTML_QuickForm_autocomplete – Class constructor
Synopsis
require_once 'HTML/QuickForm/autocomplete.php';
void constructor HTML_QuickForm_autocomplete::HTML_QuickForm_autocomplete (
string $elementName
= null
, string $elementLabel
= null
, array $options
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Input field name attribute
-
string
$elementLabel -
(optional)Input field label
-
array
$options -
Autocomplete options
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_autocomplete::setoptions()
HTML_QuickForm_autocomplete::setoptions() – Sets the options for the autocomplete input text element
Synopsis
require_once 'HTML/QuickForm/autocomplete.php';
void HTML_QuickForm_autocomplete::setOptions (
array $options
)
Description
The strings in this array will be checked by the javascript function for a match with the text being typed. In case of a match the text will be autocompleted.
Parameter
-
array
$options -
Array of options for the autocomplete input text element
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Class Summary HTML_QuickForm_date
Class Summary HTML_QuickForm_date – Class for a group of elements used to input dates (and times).
Description
The element is basically a group of <select>s that allow to input dates and times.
Class Trees for HTML_QuickForm_date
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_group
- HTML_QuickForm_date
-
HTML_QuickForm_group
-
HTML_QuickForm_element
HTML_QuickForm_date Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_group::HTML_QuickForm_group() | Class constructor |
| HTML_QuickForm_group::accept() | Accepts a renderer |
| HTML_QuickForm_group::exportValue() | As usual, to get the group's value we access its elements and call |
| HTML_QuickForm_group::getElementName() | Returns the element name inside the group such as found in the html form |
| HTML_QuickForm_group::getElements() | Gets the grouped elements |
| HTML_QuickForm_group::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_group::getGroupType() | Gets the group type based on its elements Will return 'mixed' if elements contained in the group are of different types. |
| HTML_QuickForm_group::getName() | Returns the group name |
| HTML_QuickForm_group::getValue() | Returns the value of the group |
| HTML_QuickForm_group::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_group::setElements() | Sets the grouped elements |
| HTML_QuickForm_group::setName() | Sets the group name |
| HTML_QuickForm_group::setValue() | Sets values for group's elements |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_date()
constructor HTML_QuickForm_date() – Class constructor
Synopsis
require_once 'HTML/QuickForm/date.php';
void constructor HTML_QuickForm_date::HTML_QuickForm_date (
string $elementName
= null
, mixed $elementLabel
= null
, array $options = array()
, mixed $attributes
= null
)
Description
The $options parameter controls the element's appearance. It is an associative array of the form 'option name' => 'option value'.
'language'-
Language code to use for display. Default is
'en'. date element supports many languages. If your one is not supported, send us the translation, we'll gladly include it.
'format'Format string for the date, based on PHP's date() function. The following characters are recognised:
D => Short names of days
l => Long names of days
d => Day numbers
M => Short names of months
F => Long names of months
m => Month numbers
Y => Four digit year
y => Two digit year
h => 12 hour format
H => 23 hour format
i => Minutes
s => Seconds
a => am/pm
A => AM/PM
g => 12 hour format w/o leading zeroes
W => week of the yearDefault is
'dMY'.
'minYear'Minimum year in year select. Default is 2001.
'maxYear'Maximum year in year select. Default is 2010.
On
'minYear'and'maxYear'
When
'minYear'>'maxYear'the years in the select will be displayed in descending order.
'addEmptyOption'Should an empty option be added to the top of each select box? Default is FALSE. This may be set for individual fields also, if one passes an array of the form array('format char' => TRUE, ..., 'another format char' => FALSE)
'emptyOptionValue'The value passed by the empty option. Default is
''.
'emptyOptionText'The text displayed for the empty option. Default is
' '. This may be set for individual fields also, if one passes an array of the form array('format char' => 'some text', ..., 'another format char' => 'some other text')
'optionIncrement'Step to increase the option values by. Works for
'i'and's'formats currently. Default is array('i' => 1, 's' => 1).
Parameter
-
string
$elementName -
Element's name
-
mixed
$elementLabel -
Label(s) for an element
-
array
$options -
Options to control the element's display
-
mixed
$attributes -
Either a typical HTML attribute string or an associative array
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Class Summary HTML_QuickForm_header
Class Summary HTML_QuickForm_header – A pseudo-element used for adding headers to form
Description
This element is used for adding headers to the form. Unlike usual static elements, the headers are usually rendered using a special template.
Class Trees for HTML_QuickForm_header
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_static
- HTML_QuickForm_header
-
HTML_QuickForm_static
-
HTML_QuickForm_element
HTML_QuickForm_header Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_static::HTML_QuickForm_static() | Class constructor |
| HTML_QuickForm_static::exportValue() | We override this here because we don't want any values from static elements |
| HTML_QuickForm_static::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_static::getName() | Returns the element name |
| HTML_QuickForm_static::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_static::setName() | Sets the element name |
| HTML_QuickForm_static::setText() | Sets the text |
| HTML_QuickForm_static::setValue() | Sets the text (uses the standard setValue call to emulate a form element. |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_header()
constructor HTML_QuickForm_header() – Class constructor
Synopsis
require_once 'HTML/QuickForm/header.php';
void constructor HTML_QuickForm_header::HTML_QuickForm_header (
string $elementName
= null
, string $text
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Header name
-
string
$text -
Header text
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Class Summary HTML_QuickForm_hierselect
Class Summary HTML_QuickForm_hierselect – Class to dynamically create chained HTML Select elements, each select changes the content of the next.
Description
Class to dynamically create "chained" HTML Select elements. Choosing an option in the first <select> changes the content of the second select and so on.
This element is considered as a group. Selects will be named groupName[0], groupName[1], ...
Creating a hierselect element based on values from a database table
<?php
require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm('example');
$form->setDefaults(array('test' => array('4','15')));
$sel =& $form->addElement('hierselect', 'test', 'Test:', null, '/');
$mainOptions = $db->getAssoc('select pkparent, par_desc from parent');
$result = $db->query("select fk_parent, pkchild, chi_desc from child");
while ($result->fetchInto($row)) {
$secOptions[$row[0]][$row[1]] = $row[2];
}
// Using setMainOptions and setSecOptions is now deprecated
// use setOptions.
$sel->setOptions(array($mainOptions, $secOptions));
$form->display();
?>
Creating more than two select elements is just as simple.
Creating a hierselect element with three select elements
<?php
require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm('example');
$select1[0] = 'Pop';
$select1[1] = 'Classical';
$select1[2] = 'Funeral doom';
// second select
$select2[0][0] = '--- Artist ---';
$select2[0][1] = 'Red Hot Chil Peppers';
$select2[0][2] = 'The Pixies';
$select2[1][0] = '--- Artist ---';
$select2[1][1] = 'Wagner';
$select2[1][2] = 'Strauss';
$select2[2][0] = '--- Artist ---';
$select2[2][1] = 'Pantheist';
$select2[2][2] = 'Skepticism';
// Create a third select with prices for the cds
$select3[0][0][0] = '--- Choose the artist ---';
$select3[0][1][0] = '15.00$';
$select3[0][2][1] = '17.00$';
$select3[1][0][0] = '--- Choose the artist ---';
$select3[1][1][0] = '15.00$';
$select3[1][2][1] = '17.00$';
$select3[2][0][0] = '--- Choose the artist ---';
$select3[2][1][0] = '15.00$';
$select3[2][2][1] = '17.00$';
// Create the Element
$sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
// And add the selection options
$sel->setOptions(array($select1, $select2, $select3));
$form->display();
?>
Class Trees for HTML_QuickForm_hierselect
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_group
- HTML_QuickForm_hierselect
-
HTML_QuickForm_group
-
HTML_QuickForm_element
HTML_QuickForm_hierselect Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_group::HTML_QuickForm_group() | Class constructor |
| HTML_QuickForm_group::accept() | Accepts a renderer |
| HTML_QuickForm_group::exportValue() | As usual, to get the group's value we access its elements and call |
| HTML_QuickForm_group::getElementName() | Returns the element name inside the group such as found in the html form |
| HTML_QuickForm_group::getElements() | Gets the grouped elements |
| HTML_QuickForm_group::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_group::getGroupType() | Gets the group type based on its elements Will return 'mixed' if elements contained in the group are of different types. |
| HTML_QuickForm_group::getName() | Returns the group name |
| HTML_QuickForm_group::getValue() | Returns the value of the group |
| HTML_QuickForm_group::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_group::setElements() | Sets the grouped elements |
| HTML_QuickForm_group::setName() | Sets the group name |
| HTML_QuickForm_group::setValue() | Sets values for group's elements |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_hierselect()
constructor HTML_QuickForm_hierselect() – Class constructor
Synopsis
require_once 'HTML/QuickForm/hierselect.php';
void constructor HTML_QuickForm_hierselect::HTML_QuickForm_hierselect (
string $elementName
= null
, string $elementLabel
= null
, mixed $attributes
= null
, mixed $separator
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Input field name attribute
If you are displaying several forms on one page, then hierselects in these forms should have unique names. In the other case the values for last hierselect with the same name will overwrite the values for the previous one. It is extremely difficult to cleanly fix this behaviour with current QuickForm architecture, therefore please rely on this workaround. See Request #5718.
-
string
$elementLabel -
(optional)Input field label in form
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array.
-
mixed
$separator -
String to separate the grouped elements
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_hierselect::setOptions()
HTML_QuickForm_hierselect::setOptions() – Sets the options for the select elements
Synopsis
require_once 'HTML/QuickForm/hierselect.php';
void HTML_QuickForm_hierselect::setOptions (
array $options
)
Description
Sets the options for the select elements within hierselect. Note that the actual number of selects that will be displayed is governed by the number of the elements in the array passed to this function.
Parameter
-
array
$options -
Array of options for the elements, having the following structure:
array(
// options for the first element
array(
'key_1' => 'value 1',
'key_2' => 'value 2',
...
'key_N' => 'value N',
),
// options for the second element
array(
'key_1' => array(
'key_1_1' => 'value 1.1',
'key_1_2' => 'value 1.2',
...
'key_1_M1' => 'value 1.M1'
),
'key_2' => array(
'key_2_1' => 'value 2.1',
'key_2_2' => 'value 2.2',
...
'key_2_M2' => 'value 2.M2'
),
...
'key_N' => array(
'key_N_1' => 'value N.1',
'key_N_2' => 'value N.2',
...
'key_N_MN' => 'value N.MN'
)
)
// options for further elements
...
)The options for subsequent elements should have keys for all options of the previous elements. Having a select without options is invalid HTML and will break hierselect's JavaScript. See also Bug #5218.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
since 3.2.2
Example
Setting the hierselect options
<?php
$select1 = $select2 = $select3 = array();
$select1[0] = 'Pop';
$select1[1] = 'Classical';
$select1[2] = 'Funeral doom';
// second select
$select2[0][0] = '--- Artist ---';
$select2[0][1] = 'Red Hot Chil Peppers';
$select2[0][2] = 'The Pixies';
$select2[1][0] = '--- Artist ---';
$select2[1][1] = 'Wagner';
$select2[1][2] = 'Strauss';
$select2[2][0] = '--- Artist ---';
$select2[2][1] = 'Pantheist';
$select2[2][2] = 'Skepticism';
// Create a third select with prices for the cds
$select3[0][0][0] = '--- Choose the artist ---';
$select3[0][1][0] = '15.00$';
$select3[0][2][1] = '17.00$';
$select3[1][0][0] = '--- Choose the artist ---';
$select3[1][1][0] = '15.00$';
$select3[1][2][1] = '17.00$';
$select3[2][0][0] = '--- Choose the artist ---';
$select3[2][1][0] = '15.00$';
$select3[2][2][1] = '17.00$';
// Create the Element
$sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
// And add the selection options
$sel->setOptions(array($select1, $select2, $select3));
?>
HTML_QuickForm_hierselect::setMainOptions()
HTML_QuickForm_hierselect::setMainOptions() – DEPRECATED: Sets the options for the first select
Synopsis
require_once 'HTML/QuickForm/hierselect.php';
void HTML_QuickForm_hierselect::setMainOptions (
array $options
)
Description
Format is standard key/value pairs for select elements. Example is available in the docs for setSecOptions().
This method has been deprecated. Use setOptions() instead.
Parameter
-
array
$options -
Array of options for the first select
Throws
throws no exceptions thrown
See
see HTML_QuickForm_select::loadArray(), setSecOptions().
Note
This function can not be called statically.
This function is deprecated. That means that future versions of this package may not support it anymore.
Deprecated in release 3.2.2
HTML_QuickForm_hierselect::setSecOptions()
HTML_QuickForm_hierselect::setSecOptions() – DEPRECATED: Sets the options for the secondary select
Synopsis
require_once 'HTML/QuickForm/hierselect.php';
void HTML_QuickForm_hierselect::setSecOptions (
array $options
)
Description
Sets the options for the secondary select. Options are passed as a two-dimensional array, where the first key is parent id and the second key is child id, as it is needed to know the parent option to which the secondary option relates.
This method has been deprecated. Use setOptions() instead.
Parameter
-
array
$options -
Array of options for the second select
Throws
throws no exceptions thrown
See
see setMainOptions().
Note
This function can not be called statically.
This function is deprecated. That means that future versions of this package may not support it anymore.
Deprecated in release 3.2.2
Example
Setting the hierselect options
<?php
$hierSel =& $form->addElement('hierselect', 'test', 'Test:', null, '/');
$main[0] = 'Pop';
$main[1] = 'Classical';
$main[2] = 'Funeral doom';
$sec[0][1] = 'Red Hot Chili Peppers';
$sec[0][2] = 'The Pixies';
$sec[1][3] = 'Wagner';
$sec[1][4] = 'Strauss';
$sec[2][5] = 'Pantheist';
$sec[2][6] = 'Skepticism';
$hierSel->setMainOptions($main);
$hierSel->setSecOptions($sec);
?>
Class Summary HTML_QuickForm_html
Class Summary HTML_QuickForm_html – A pseudo-element used for adding raw HTML to form (deprecated)
Description
A pseudo-element used for adding raw HTML to form output. Its contents are output as is, without applying any element template.
This element is deprecated. No fixes and changes to its behaviour will be done and it will be removed in the next major version of the package. If you really need to add raw html to the form, you may consider using 'static' element instead.
The element can be used with the Default Renderer only, all other Renderers completely ignore this. Consider using some template-based renderer instead of relying on this feature.
Class Trees for HTML_QuickForm_html
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_static
- HTML_QuickForm_html
-
HTML_QuickForm_static
-
HTML_QuickForm_element
HTML_QuickForm_html Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_static::HTML_QuickForm_static() | Class constructor |
| HTML_QuickForm_static::exportValue() | We override this here because we don't want any values from static elements |
| HTML_QuickForm_static::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_static::getName() | Returns the element name |
| HTML_QuickForm_static::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_static::setName() | Sets the element name |
| HTML_QuickForm_static::setText() | Sets the text |
| HTML_QuickForm_static::setValue() | Sets the text (uses the standard setValue call to emulate a form element. |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_html()
constructor HTML_QuickForm_html() – Class constructor
Synopsis
require_once 'HTML/QuickForm/html.php';
void constructor HTML_QuickForm_html::HTML_QuickForm_html (
string $text
= null
)
Description
This package is not documented yet.
Parameter
-
string
$text -
raw HTML to add
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Class Summary HTML_QuickForm_link
Class Summary HTML_QuickForm_link – HTML class for a link type field
Description
This is used to add <a href="...">...</a> tag within a standard element template.
Class Trees for HTML_QuickForm_link
-
HTML_Common
-
HTML_QuickForm_element
-
HTML_QuickForm_static
- HTML_QuickForm_link
-
HTML_QuickForm_static
-
HTML_QuickForm_element
HTML_QuickForm_link Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_static::HTML_QuickForm_static() | Class constructor |
| HTML_QuickForm_static::exportValue() | We override this here because we don't want any values from static elements |
| HTML_QuickForm_static::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_static::getName() | Returns the element name |
| HTML_QuickForm_static::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_static::setName() | Sets the element name |
| HTML_QuickForm_static::setText() | Sets the text |
| HTML_QuickForm_static::setValue() | Sets the text (uses the standard setValue call to emulate a form element. |
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_link()
constructor HTML_QuickForm_link() – Class constructor
Synopsis
require_once 'HTML/QuickForm/link.php';
void constructor HTML_QuickForm_link::HTML_QuickForm_link (
mixed $elementName
= null
, string $elementLabel
= null
, string $href
= null
, string $text
= null
, mixed $attributes
= null
)
Description
This package is not documented yet.
Parameter
-
mixed
$elementName
-
string
$elementLabel -
(optional)Link label
-
string
$href -
(optional)Link href
-
string
$text -
(optional)Link display text
-
mixed
$attributes -
(optional)Either a typical HTML attribute string or an associative array
Throws
throws
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_link::setHref()
HTML_QuickForm_link::setHref() – Sets the links href
Synopsis
require_once 'HTML/QuickForm/link.php';
void HTML_QuickForm_link::setHref (
string $href
)
Description
This is just a shortcut for
<?php
$element->updateAttributes(array('href' => $href));
?>
Parameter
-
string
$href
Throws
throws
Note
since 1.0
This function can not be called statically.
Class Summary HTML_QuickForm_static
Class Summary HTML_QuickForm_static – HTML class for static data
Description
A static element is an element that cannot have a submit value and thus cannot change due to user input. Such elements are usually used to improve form presentation. Note that elements of HTML_QuickForm_static type are by default rendered inside the same template as the normal form elements.
Class Trees for HTML_QuickForm_static
-
HTML_Common
-
HTML_QuickForm_element
- HTML_QuickForm_static
-
HTML_QuickForm_element
| Class | Summary |
|---|---|
| HTML_QuickForm_header | A pseudo-element used for adding headers to form |
| HTML_QuickForm_html | A pseudo-element used for adding raw HTML to form |
| HTML_QuickForm_link | HTML class for a link type field |
HTML_QuickForm_static Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_static()
constructor HTML_QuickForm_static() – Class constructor
Synopsis
require_once 'HTML/QuickForm/static.php';
void constructor HTML_QuickForm_static::HTML_QuickForm_static (
string $elementName
= null
, mixed $elementLabel
= null
, string $text
= null
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
Name of the element
-
mixed
$elementLabel -
(optional)Label
-
string
$text -
(optional)Display text
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_static::setText()
HTML_QuickForm_static::setText() – Sets the text
Synopsis
require_once 'HTML/QuickForm/static.php';
void HTML_QuickForm_static::setText (
string $text
)
Description
This text is essentially the static element itself. Note that setValue() is an alias for setText().
Parameter
-
string
$text -
text of the element
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Using groups
To be written.
HTML_QuickForm::addGroup()
HTML_QuickForm::addGroup() – Adds an element group
Synopsis
require_once 'HTML/QuickForm.php';
object &HTML_QuickForm::addGroup (
array $elements
, string $name
= null
, mixed $groupLabel = ''
, string $separator
= null
, string $appendName
= true
)
Description
Adds an element group.
Parameter
-
array
$elements -
array of elements composing the group
-
string
$name -
(optional) group name
-
mixed
$groupLabel -
(optional) group label
-
mixed
$separator -
(optional) string or array of strings to separate elements
-
boolean
$appendName -
(optional) specify whether the group name should be used in the form element name: groupName[elementName] vs elementName
Return value
return reference to added group of elements
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_INVALID_ELEMENT_NAME | Element '$elementName' already exists in HTML_QuickForm::addElement() |
Tried to add a group having a name of an existing element | Choose a different name for a group |
Note
since 2.8
This function can not be called statically.
Example
Using addGroup()
<?php
$group[] =& HTML_QuickForm::createElement('text', 'first', 'First');
$group[] =& HTML_QuickForm::createElement('text', 'last', 'Last');
$form->addGroup($group, 'name', 'Name:', ', ');
?>
Class Summary HTML_QuickForm_group
Class Summary HTML_QuickForm_group – HTML class for a form element group
Description
Groups allow you to combine several individual elements into one entity and to use it as usual form element. Most of the group's methods use the methods of the grouped elements to do their job. For example, groups do not have values themselves, their setValue() and getValue() methods just call the appropriate methods of grouped elements to set and get their values.
Groups can be used both for visual grouping of the elements (e.g. putting "Submit" and "Reset" buttons on one line), grouping of the elements with the same name (e.g. groups of checkboxes and radiobuttons) and logical grouping of the elements (e.g. group for person's name consisting of two text fields for first and last name).
Class Trees for HTML_QuickForm_group
-
HTML_Common
-
HTML_QuickForm_element
- HTML_QuickForm_group
-
HTML_QuickForm_element
| Class | Summary |
|---|---|
| HTML_QuickForm_date | Class for a group of elements used to input dates (and times). |
| HTML_QuickForm_hierselect | Class to dynamically create two HTML Select elements The first select changes the content of the second select. |
HTML_QuickForm_group Inherited Methods
| Method Name | Summary |
|---|---|
| Constructor HTML_QuickForm_element::HTML_QuickForm_element() | Class constructor |
| HTML_QuickForm_element::accept() | Accepts a renderer |
| HTML_QuickForm_element::apiVersion() | Returns the current API version |
| HTML_QuickForm_element::exportValue() | Returns a 'safe' element's value |
| HTML_QuickForm_element::freeze() | Freeze the element so that only its value is returned |
| HTML_QuickForm_element::getFrozenHtml() | Returns the value of field without HTML tags |
| HTML_QuickForm_element::getLabel() | Returns display text for the element |
| HTML_QuickForm_element::getName() | Returns the element name |
| HTML_QuickForm_element::getType() | Returns element type |
| HTML_QuickForm_element::getValue() | Returns the value of the form element |
| HTML_QuickForm_element::isFrozen() | Returns whether or not the element is frozen |
| HTML_QuickForm_element::onQuickFormEvent() | Called by HTML_QuickForm whenever form event is made on this element |
| HTML_QuickForm_element::setLabel() | Sets display text for the element |
| HTML_QuickForm_element::setName() | Sets the input field name |
| HTML_QuickForm_element::setPersistantFreeze() | Sets wether an element value should be kept in an hidden field when the element is frozen or not |
| HTML_QuickForm_element::setValue() | Sets the value of the form element |
| HTML_QuickForm_element::unfreeze() | Unfreezes the form element |
constructor HTML_QuickForm_group()
constructor HTML_QuickForm_group() – Class constructor
Synopsis
require_once 'HTML/QuickForm/group.php';
void constructor HTML_QuickForm_group::HTML_QuickForm_group (
string $elementName
= null
, array $elementLabel
= null
, array $elements
= null
, mixed $separator
= null
, bool $appendName
= true
)
Description
This package is not documented yet.
Parameter
-
string
$elementName -
(optional)Group name
-
array
$elementLabel -
(optional)Group label
-
array
$elements -
(optional)Group elements
-
mixed
$separator -
(optional)Use a string for one separator, use an array to alternate the separators.
-
boolean
$appendName -
(optional)whether to change elements' names to the form $groupName[$elementName] or leave them as is.
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm_group::getElementName()
HTML_QuickForm_group::getElementName() – Returns the name of an element inside the group
Synopsis
require_once 'HTML/QuickForm/group.php';
mixed HTML_QuickForm_group::getElementName (
mixed $index
)
Description
Returns the name of an element inside the group. This is the name that will be shown in the form HTML output.
Parameter
-
mixed
$index -
Element name or element index in the group
Return value
returns string with element name, false if not found
Throws
throws no exceptions thrown
Note
since 3.0
This function can not be called statically.
HTML_QuickForm_group::getElements()
HTML_QuickForm_group::getElements() – Gets the grouped elements
Synopsis
require_once 'HTML/QuickForm/group.php';
array &HTML_QuickForm_group::getElements (
)
Description
This package is not documented yet.
Throws
throws no exceptions thrown
Note
since 2.4
This function can not be called statically.
HTML_QuickForm_group::getGroupType()
HTML_QuickForm_group::getGroupType() – Gets the group type based on its elements.
Synopsis
require_once 'HTML/QuickForm/group.php';
string HTML_QuickForm_group::getGroupType (
)
Description
Will return 'mixed' if elements contained in the group are of different types.
Return value
returns group elements type
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_group::setElements()
HTML_QuickForm_group::setElements() – Sets the grouped elements
Synopsis
require_once 'HTML/QuickForm/group.php';
void HTML_QuickForm_group::setElements (
array $elements
)
Description
This package is not documented yet.
Parameter
-
array
$elements -
Array of elements
Throws
throws no exceptions thrown
Note
since 1.1
This function can not be called statically.
Working with elements' values
This section covers the methods QuickForm offers for managing form element's values and working with submitted values.
Getting, setting and processing element values
HTML_QuickForm::setConstants()
HTML_QuickForm::setConstants() – Sets constant form values
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::setConstants (
array $constantValues
= null
, mixed $filter
= null
)
Description
Sets constant form values. These values won't be overridden by either default (set via setDefaults()) or submitted (POST or GET) values.
Parameter
-
array
$constantValues -
values used to fill the form, array('element name' => 'element value')
-
mixed
$filter -
(optional) filter(s) to apply to all default values
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_INVALID_FILTER | Callback function does not exist in QuickForm::setConstants() | Tried to pass a name of a non-existant function as a callback | Check spelling |
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::setDefaults()
HTML_QuickForm::setDefaults() – Sets default form values
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::setDefaults (
array $defaultValues
= null
, mixed $filter
= null
)
Description
Sets default form values. There are overriden by either constant (set via setConstants()) or submitted (POST or GET) values.
Parameter
-
array
$defaultValues -
values used to fill the form, array('element name' => 'element value')
-
mixed
$filter -
(optional) filter(s) to apply to all default values
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_INVALID_FILTER | Callback function does not exist in QuickForm::setDefaults() | Tried to pass a name of a non-existant function as a callback | Check spelling |
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::isSubmitted()
HTML_QuickForm::isSubmitted() – Tells whether the form was already submitted
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::isSubmitted (
void
)
Description
Tells whether the form was already submitted. Using this method when
$trackSubmit parameter of QuickForm's
constructor
is used is more reliable than checking whether form's submit
values are empty.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
since 3.2.5
HTML_QuickForm::exportValue()
HTML_QuickForm::exportValue() – Returns the element's "safe" value
Synopsis
require_once 'HTML/QuickForm.php';
mixed HTML_QuickForm::exportValue (
string $element
)
Description
This method first tries to find a cleaned-up submitted value, it will return a value set by setValue()/setDefaults()/setConstants() if submitted value does not exist for the given element.
The value that couldn't have possibly been submitted (e.g.: an option that is not present in <select> element's option list) is not considered valid and is not returned.
As the values returned by this method and by exportValues() are expected to be immediately processed and/or stored somewhere, values for file elements that obviously have special processing needs are not returned.
Parameter
-
string
$element -
Name of the element
Return value
return element value
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Element '$element' does not exist in HTML_QuickForm::exportValue() |
Tried to get a value of a non-existant element | Check the element's name spelling |
Note
since 3.1
This function can not be called statically.
HTML_QuickForm::exportValues()
HTML_QuickForm::exportValues() – Returns "safe" elements' values
Synopsis
require_once 'HTML/QuickForm.php';
array HTML_QuickForm::exportValues (
mixed $elementList
= null
)
Description
Returns the values for the form elements. First it tries to return filtered submitted values, if there were none then it takes the values set by setDefaults() or setConstants().
Unlike getSubmitValues(), this will return only the values corresponding to the elements added to the form and only the values that could actually be submitted: if we have 'Yes'/'No' radiobuttons 'Maybe' will not be considered a valid submit value. You also cannot get values for file elements via this method.
Parameter
-
mixed
$elementList -
Array/string of element names, whose values we want. If not set then return all elements.
Return value
return An assoc array of elements' values
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Element '$element' does not exist in HTML_QuickForm::exportValue() |
Tried to get a value of a non-existant element | Check the element's name spelling |
Note
since 3.1
This function can not be called statically.
HTML_QuickForm::getElementValue()
HTML_QuickForm::getElementValue() – Returns the element's raw value
Synopsis
require_once 'HTML/QuickForm.php';
mixed &HTML_QuickForm::getElementValue (
string $element
)
Description
Returns the element's raw value such as submitted by the form (not filtered), set by setDefaults() or setConstants().
Parameter
-
string
$element -
Element name
Return value
return element value
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Element '$element' does not exist in HTML_QuickForm::getElementValue() |
Tried to get a value of a non-existant element | Check the element's name spelling |
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::getSubmitValue()
HTML_QuickForm::getSubmitValue() – Returns the submitted element's value
Synopsis
require_once 'HTML/QuickForm.php';
mixed HTML_QuickForm::getSubmitValue (
string $element
)
Description
Returns the submitted element's value. The value is filtered.
Parameter
-
string
$element -
Element name
Return value
return submitted element value or NULL if not set
Throws
throws no exceptions thrown
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::getSubmitValues()
HTML_QuickForm::getSubmitValues() – Returns the values submitted by the form
Synopsis
require_once 'HTML/QuickForm.php';
array HTML_QuickForm::getSubmitValues (
bool $mergeFiles
= false
)
Description
Returns the values submitted by the form, possibly with uploaded files as well.
Parameter
-
boolean
$mergeFiles -
Whether uploaded files should be returned too
Throws
throws no exceptions thrown
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::process()
HTML_QuickForm::process() – Performs the form data processing
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::process (
mixed $callback
, bool $mergeFiles
= true
)
Description
Performs the form data processing. It actually calls the $callback passing the submitted values (and files, when $mergeFiles=TRUE) to it.
Parameter
-
mixed
$callback -
Callback, either function name or array(&$object, 'method')
-
boolean
$mergeFiles -
Whether uploaded files should be processed too
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_INVALID_PROCESS | Callback function does not exist in QuickForm::process() | Tried to pass a name of a non-existant function as a callback | Check spelling |
Note
since 1.0
This function can not be called statically.
Validation and filters
QuickForm also provides validation rules support. You can code your own validation rules, register them in QuickForm and then call them in your script. By default, QuickForm can handle validation against regular expressions (preg_match style) and check for required elements. If you want client-side validation, QuickForm can generate the javascript code needed. Server-side validation is always on by default.
QuickForm can also make use of filters for data import into the form or for data processing once the form has been submitted. Filters work the same way as rules except that you don't need to register them. You write your filter functions and call them in your script. You can call any php function (ie. trim, addslashes, htmlentities, etc.) and have them applied recursively to your element values.
Introduction - validation and filters
Introduction - validation and filters – How to process submitted data
Validation rules
QuickForm makes client-side and server-side form validation easy. It allows for validation against regular expressions or custom functions and methods. You can define your own validation rules and apply them to the elements or groups you want. In this section, we will explore the different possibilities QuickForm offers to make validation easier.
QuickForm can verify if required elements are filled when the form is submitted. This works with every type of elements or groups, integer 0 is not considered as an empty value.
<?php
require_once 'HTML/QuickForm.php';
$form = new HTML_QuickForm('myform', 'post');
$form->addElement('text', 'email', 'Your email:');
$form->addElement('submit', 'submit', 'Submit');
// Validation rules
$form->addRule('email', 'E-Mail is required', 'required');
// Validation
if ($form->validate()) {
$form->freeze();
}
$form->display();
?>
On empty elements validation
If the element is empty, no validation rules other than
requiredare checked for it. This means that empty element can be invalid only when it is required.
On required uploads
requiredrule does not work for file elements. Useuploadedfile.
The HTML_QuickForm::validate() method will scan through each rules in the order they have been set. If a rule is not validated, the error message corresponding to the element will be displayed and the form will be shown once again. You can use templates to set the position of this error message. The order you decide to set your validation rules is important because it will determine which error message is used.
Client-side validation
QuickForm can generate the javascript necessary to validate the form on the client side. This feature works for all standard elements and for groups. Server side validation is always performed in case the client has javascript turned off.
<?php
$form->addRule('email', 'E-Mail is required', 'required', null, 'client');
?>
By setting the parameter
'client', you trigger the javascript automatic generation.
Built-in validation rules
QuickForm offers a few registered rules that are often used when validating
forms. Some of the rules may need an extra $format parameter
passed to addRule() /
addGroupRule()
to work properly.
| Name | Description | $format parameter |
|---|---|---|
required |
value is not empty | |
maxlength |
value must not exceed given number of characters | number of characters, integer |
minlength |
value must have more than given number of characters | number of characters, integer |
rangelength |
value must have between min and max characters | array(min characters, max characters) |
regex |
value must pass the regular expression | regular expression to check, string |
email |
value is a correctly formatted email | whether to perform an additional domain check via checkdnsrr() function, boolean |
lettersonly |
value must contain only letters | |
alphanumeric |
value must contain only letters and numbers | |
numeric |
value must be a number | |
nopunctuation |
value must not contain punctuation characters | |
nonzero |
value must be a number not starting with 0 | |
compare |
The rule allows to compare the values of two form fields. This can be used for e.g. 'Password repeat must match password' kind of rule. Please note that you need to pass an array of elements' names to compare as a first parameter to addRule(). | Type of comparison to perform, string:
|
callback |
This rule allows to use an external function/method for validation. This can be done either explicitly, by passing a callback as a format parameter or implicitly, by registering it via registerRule(). | Function/method to use, callback. |
| Validation rules for file uploads | ||
uploadedfile |
required file upload | |
maxfilesize |
the file size must not exceed the given number of bytes | maximum file size, integer |
mimetype |
the file must have a correct MIME type | either a string for single allowed MIME type, or an array of allowed MIME types |
filename |
the filename must match the given regex | regular expression to test, string |
On rules for file uploads
These rules are defined in
HTML/QuickForm/file.php, and are automatically registered when afiletype element is added to the form. These rules are server-side only, for obvious reasons.
Usage of builtin rules is covered in rules-builtin.php
example provided with the package. The rules-custom.php
example covers the usage of custom rule classes and callback
type rules. It also contains a NumericRange class for
checking whether a number is between a maximum and a minimum.
Validation classes
Since release 3.2 all builtin validation is performed by subclasses of HTML_QuickForm_Rule class. You can create your own subclass of it and implement validate() and getValidationScript() methods. Consult the source for the examples.
Validation functions and methods
When you need a more complex validation, QuickForm can use your own custom-made functions to validate an element or a group. QuickForm can also call a method of a class. This way, it is possible to use PEAR's Validate package or any other class. If you want to use your own functions, you basically have two options:
- Register the function via registerRule() using
'callback'as$typeand giving the new rule a custom$ruleName. Later you add the rule with this name via addRule() like any buitin rule. - Add the rule of
callbacktype via addRule() passing the name of your function as$format. This way you'll have less characters to type, but will be unable to pass additional data to your function.
Email validation function
<?php
/**
* Validate an email address
*
* @param string $email Email address to validate
* @param boolean $domainCheck Check if the domain exists
*/
function checkEmail($email, $domainCheck = false)
{
if (preg_match('/^[a-zA-Z0-9\._-]+\@(\[?)[a-zA-Z0-9\-\.]+'.
'\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/', $email)) {
if ($domainCheck && function_exists('checkdnsrr')) {
list (, $domain) = explode('@', $email);
if (checkdnsrr($domain, 'MX') || checkdnsrr($domain, 'A')) {
return true;
}
return false;
}
return true;
}
return false;
}
$form->registerRule('checkmail', 'callback', 'checkEmail');
$form->addRule('email', 'Email is incorrect', 'checkmail', true);
?>
You can pass an extra parameter of the type you want to your function when set with HTML_QuickForm::addRule(). Here we used TRUE to enable the DNS check of our function.
If you use a method, you must specify the class your method is in. Use this syntax when you register your rule:
<?php
// Method checkEmail is in class Validate
$form->registerRule('checkmail', 'callback', 'checkEmail', 'Validate');
?>
You can also use a javascript function to validate your form, give it the same name as your PHP function, have it return a boolean and set the
'client'parameter.
Group validation
Groups of elements can be validated the same way other elements are, or use a more complex validation scheme. To validate a group as a whole, just use HTML_QuickForm::addRule(). The group elements' values will be passed to the validation function as an array.
You can have more complex validation for your groups using the HTML_QuickForm::addGroupRule() method. This allows for a per element validation. It also makes it possible to specify the number of elements that need to be valid for the group to be valid too.
Complex group validation
<?php
// Group
$id[] = &HTML_QuickForm::createElement('text', 'username', 'Username');
$id[] = &HTML_QuickForm::createElement('text', 'code', 'Code');
$form->addGroup($id, 'id', 'Your ID:', '-');
// Validation rules per element
$rule['username'][] = array('Username is required', 'required');
$rule['username'][] = array('Username contains only letters', 'lettersonly');
$rule['username'][] = array('Username has between 5-8 characters', 'rangelength', array(5, 8));
$rule['code'][] = array('Code is required', 'required');
$rule['code'][] = array('Code contains numbers only', 'regex', '/^\d+$/');
$rule['code'][] = array('Code is 5 numbers long', 'rangelength', array(5, 5));
$form->addGroupRule('id', $rule);
?>
In this example, we have set rules for the elements inside our group. Instead of using their names, we could have used their index (determined by the order they were created) in the group, it would speed up the validation process.
The following example takes the same group and will validate the form only if at least one of our two elements is not empty. To achieve this, we use the howmany parameter and set it to 1.
<?php
$form->addGroupRule('id', 'Fill at least one element', 'required', null, 1);
?>
Conclusion
You have seen that QuickForm makes it easy to validate your elements and groups without having to write all the usually necessary code to find the different values. It takes care of required elements, generates the javascript automatically and adds a lot of flexibility by allowing you to use your own validation functions and regular expressions. It's time to experiment...
Filters
If we add a rule like
<?php
$form->addRule('element', 'The element is required', 'required');
?>to the form, then any input will satisfy it, including, for example, a single space. This is because the rule simply ensures that there are one or more characters present, and a space character satisfies the rule.
Of course this can be fixed by making a custom regex rule, but there is an easier solution. We usually do not care about leading and trailing spaces at all, and we can make the element's value pass through builtin trim() function before doing any validation on it:
<?php
$form->applyFilter('element', 'trim');
?>
Filters are applied recursively, which means that trim() on an array will work, too. You can pass any valid callback as an argument to applyFilter() method.
Use filters if you want to 'sanitize' user input and do not really care about invalid values.
HTML_QuickForm::addRule()
HTML_QuickForm::addRule() – Adds a validation rule for the given field
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::addRule (
mixed $element
, string $message
, string $type
, string $format = ''
, string $validation = 'server'
, boolean $reset
= false
, boolean $force
= false
)
Description
If the element is in fact a group, it will be considered as a whole, an array of group elements' values will be passed to validation function. To validate grouped elements as separate entities, use addGroupRule().
Parameter
-
mixed
$element -
Form element name(s). Currently the only builtin rule that expects and correctly handles an array here is
compare:<?php $form->addElement('password', 'cmpPasswd', 'Password:'); $form->addElement('password', 'cmpRepeat', 'Repeat password:'); $form->addRule(array('cmpPasswd', 'cmpRepeat'), 'The passwords do not match', 'compare', null, 'client'); ?>All other builtin rules will only handle a single element name.
callbackrules can also handle an array here, but the callback function you provide will obviously need to properly handle an array of values.
-
string
$message -
Message to display for invalid data
-
string
$type -
Rule type, use getRegisteredRules() to get types. You can also pass a classname for a descendant of HTML_QuickForm_Rule or an instance of such class.
-
string
$format -
(optional) Required for extra rule data
-
string
$validation -
(optional) Where to perform validation: "server", "client"
-
boolean
$reset -
For client-side validation: reset the form element to its original value if there is an error?
-
boolean
$force -
Force the rule to be applied, even if the target form element does not exist
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Element '$element' does not exist in HTML_QuickForm::addRule() |
Tried to add a rule for a non-existant element | Check the element's name spelling or use $force to suppress the error. |
| QUICKFORM_INVALID_RULE | Rule '$type' is not registered in HTML_QuickForm::addRule() |
Rule is not known to QuickForm | Check rule type spelling or use HTML_QuickForm::registerRule(). |
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::addGroupRule()
HTML_QuickForm::addGroupRule() – Adds a validation rule for the given group
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::addGroupRule (
string $group
, mixed $arg1
, string $type = ''
, string $format = ''
, int $howmany = 0
, string $validation = 'server'
, bool $reset
= false
)
Description
Adds a validation rule for the given group of elements
Only groups with a name can be assigned a validation rule. Use addGroupRule() when you need to validate elements inside the group. Also use addRule() if you need to validate the group as a whole.
Parameter
-
string
$group -
Form group name
-
mixed
$arg1 -
Array for multiple elements or error message string for one element. If this is the array, its structure is the following:
array (
'element name or index' => array(
array(rule data),
...
array(rule data)
),
...
'element name or index' => array(
array(rule data),
...
array(rule data)
)
)rule data here matches the parameters' order and meaning for addRule() method.
If this parameter is an array, all the subsequent parameters are ignored. You should pass all the modifiers for the rules being added within this array (see the example below).
-
string
$type -
(optional) Rule type. Use getRegisteredRules() to get types. You can also pass a classname for a descendant of HTML_QuickForm_Rule or an instance of such class.
-
string
$format -
(optional) Required for extra rule data
-
integer
$howmany -
(optional) How many valid elements should be in the group
-
string
$validation -
(optional)Where to perform validation: "server", "client"
-
boolean
$reset -
Client-side: whether to reset the element's value to its original state if validation failed.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Group '$group' does not exist in HTML_QuickForm::addGroupRule() |
Tried to add a rule for a non-existant group | Check the group name spelling |
| QUICKFORM_NONEXIST_ELEMENT | Element '$elementIndex' not found in group '$group' in HTML_QuickForm::addGroupRule() |
$arg1 is an array and contains an index for an element not present in a group |
Check the element index spelling |
| QUICKFORM_INVALID_RULE | Rule '$type' is not registered in HTML_QuickForm::addGroupRule() |
Rule is not known to QuickForm | Check rule type spelling or use HTML_QuickForm::registerRule(). |
Note
since 2.5
This function can not be called statically.
Example
Using addGroupRule()
<?php
// a group of 4 checkboxes
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'A', null, 'A');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'B', null, 'B');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'C', null, 'C');
$checkbox[] = &HTML_QuickForm::createElement('checkbox', 'D', null, 'D');
$form->addGroup($checkbox, 'ichkABCD', 'ABCD:', array(' ', '<br />'));
// Simple rule: at least 2 checkboxes should be checked
$form->addGroupRule('ichkABCD', 'Please check at least two boxes', 'required', null, 2);
$idGrp[] = &HTML_QuickForm::createElement('text', 'lastname', 'Name', array('size' => 30));
$idGrp[] = &HTML_QuickForm::createElement('text', 'code', 'Code', array('size' => 5, 'maxlength' => 4));
$form->addGroup($idGrp, 'id', 'ID:', ', ');
// Complex rule for group's elements
$form->addGroupRule('id', array(
'lastname' => array(
array('Name is letters only', 'lettersonly'),
array('Name is required', 'required', null, 'client')
),
'code' => array(
array('Code must be numeric', 'numeric')
)
));
?>
HTML_QuickForm::addFormRule()
HTML_QuickForm::addFormRule() – Adds a global validation rule
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::addFormRule (
mixed $rule
)
Description
This should be used when you want to add a rule involving several fields or if you want to use some completely custom validation for your form. The rule function/method should return TRUE in case of successful validation and array('element name' => 'error') when there were errors.
Parameter
-
mixed
$rule -
A valid callback
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_INVALID_RULE | Callback function does not exist in HTML_QuickForm::addFormRule() | Tried to pass a name of a non-existant function as a callback | Check spelling |
Note
since 3.1
This function can not be called statically.
Example
Using addFormRule()
<?php
require_once ('HTML/QuickForm.php');
$form = new HTML_QuickForm();
// the function checks whether the passwords are the same
function cmpPass($fields)
{
if (strlen($fields['passwd1']) && strlen($fields['passwd2']) &&
$fields['passwd1'] != $fields['passwd2']) {
return array('passwd1' => 'Passwords are not the same');
}
return true;
}
$form->addElement('password', 'passwd1', 'Enter password');
$form->addElement('password', 'passwd2', 'Confirm password');
$form->addFormRule('cmpPass');
?>
HTML_QuickForm::isElementRequired()
HTML_QuickForm::isElementRequired() – Returns whether the form element is required
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::isElementRequired (
string $element
)
Description
Returns whether or not the form element is required, i.e. whether a 'required' rule was added for it.
Parameter
-
string
$element -
Form element name
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::validate()
HTML_QuickForm::validate() – Performs the server side validation
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::validate (
void
)
Description
Performs the server side validation.
Return value
return TRUE if no error found
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::getElementError()
HTML_QuickForm::getElementError() – Returns error corresponding to validated element
Synopsis
require_once 'HTML/QuickForm.php';
string HTML_QuickForm::getElementError (
string $element
)
Description
Returns error corresponding to validated element. Errors are usually assigned to elements by validate() method.
Parameter
-
string
$element -
Name of form element to check
Return value
return error message corresponding to checked element
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::setElementError()
HTML_QuickForm::setElementError() – Set error message for a form element
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::setElementError (
string $element
, string $message
)
Description
Set error message for a form element. Errors are usually assigned to elements by validate() method. Use this if you need to explicitly set error message for an element.
Parameter
-
string
$element -
Name of form element to set error for
-
string
$message -
Error message
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::registerRule()
HTML_QuickForm::registerRule() – Registers a new validation rule
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::registerRule (
string $ruleName
, string $type
, string $data1
, string $data2
= null
)
Description
Registers a new validation rule
Parameter
-
string
$ruleName -
Name of validation rule
-
string
$type -
Either:
'regex'or'callback'('function'is also kept for backward compatibility). If registering a subclass of HTML_QuickForm_Rule you can pass anything here, preferrably NULL or empty string.
-
string
$data1 -
Name of function, regular expression, classname of HTML_QuickForm_Rule subclass or an instance of such class.
The callback function needs to return
trueorfalse, determining if the rule is passed or not.
-
string
$data2 -
Object parent of above function, name of the file containing the subclass of HTML_QuickForm_Rule.
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::getRegisteredRules()
HTML_QuickForm::getRegisteredRules() – Returns registered validation rules
Synopsis
require_once 'HTML/QuickForm.php';
array HTML_QuickForm::getRegisteredRules (
void
)
Description
Returns an array of registered validation rules.
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::isRuleRegistered()
HTML_QuickForm::isRuleRegistered() – Returns whether the rule is supported
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::isRuleRegistered (
string $name
)
Description
Returns whether or not the given rule is supported. New rules are registered via registerRule() method.
Parameter
-
string
$name -
Validation rule name
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::applyFilter()
HTML_QuickForm::applyFilter() – Applies a filter for the given field(s)
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::applyFilter (
mixed $element
, mixed $filter
)
Description
Applies a data filter for the given field(s). Filter is applied recursively.
Parameter
-
mixed
$element -
Form element name or array of such names. Special name
'__ALL__'means all the form elements.
-
mixed
$filter -
Callback, either function name or array(&$object, 'method')
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_INVALID_FILTER | Callback function does not exist in QuickForm::applyFilter() | Tried to pass a name of a non-existant function as a callback | Check spelling |
Note
since 2.0
This function can not be called statically.
Outputting the form
Your form can be customised in many ways. QuickForm can use different kind of renderers and provides a default one which allows for customization of the form, the elements, the error messages, the headers, the required elements note and the required elements sign. You can also write your own renderers.
Form customization and output helpers
HTML_QuickForm::freeze()
HTML_QuickForm::freeze() – "Freezes" the form's elements
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::freeze (
mixed $elementList
= null
)
Description
Freezes the elements: elements' values will be displayed without HTML input tags.
Parameter
-
mixed
$elementList -
array or string of element(s) to be frozen. If NULL then all the form's elements will be frozen.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| QUICKFORM_NONEXIST_ELEMENT | Element '$element' does not exist in HTML_QuickForm::freeze() |
Tried to freeze a non-existant element | Check the element's name spelling |
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::isElementFrozen()
HTML_QuickForm::isElementFrozen() – Checks whether the element is frozen
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::isElementFrozen (
string $element
)
Description
Returns whether or not the form element is frozen.
Parameter
-
string
$element -
Form element name
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::isFrozen()
HTML_QuickForm::isFrozen() – Checks whether the form is frozen
Synopsis
require_once 'HTML/QuickForm.php';
boolean HTML_QuickForm::isFrozen (
void
)
Description
Returns whether or not the whole form is frozen.
Throws
throws no exceptions thrown
Note
since 3.0
This function can not be called statically.
HTML_QuickForm::setRequiredNote()
HTML_QuickForm::setRequiredNote() – Sets required note
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::setRequiredNote (
string $note
)
Description
Sets the required note. This note is usually displayed below the form when the form contains required fields.
Parameter
-
string
$note -
Message indicating some elements are required
Throws
throws no exceptions thrown
Note
since 1.1
This function can not be called statically.
HTML_QuickForm::setJsWarnings()
HTML_QuickForm::setJsWarnings() – Sets JavaScript warning messages
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::setJsWarnings (
string $pref
, string $post
)
Description
Sets JavaScript warning messages: the first is displayed before element errors, the second after them. Useless if the form had no rules added with 'client' modifier.
Parameter
-
string
$pref -
Prefix warning
-
string
$post -
Postfix warning
Throws
throws no exceptions thrown
Note
since 1.1
This function can not be called statically.
HTML_QuickForm::getRequiredNote()
HTML_QuickForm::getRequiredNote() – Returns the required note
Synopsis
require_once 'HTML/QuickForm.php';
string HTML_QuickForm::getRequiredNote (
void
)
Description
Returns the required note. This note is usually displayed below the form when the form contains required fields.
Throws
throws no exceptions thrown
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::getValidationScript()
HTML_QuickForm::getValidationScript() – Returns the client side validation script
Synopsis
require_once 'HTML/QuickForm.php';
string HTML_QuickForm::getValidationScript (
void
)
Description
Returns JavaScript used to validate the form on client side. Returns an empty string if no rules were added with 'client' modifier.
Throws
throws no exceptions thrown
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::accept()
HTML_QuickForm::accept() – Accepts a renderer
Synopsis
require_once 'HTML/QuickForm.php';
void HTML_QuickForm::accept (
object &$renderer
)
Description
Accepts a renderer. This method is a part of the Visitor design pattern implementation.
Parameter
-
object
&$renderer -
HTML_QuickForm_Renderer object
Throws
throws no exceptions thrown
Note
since 3.0
This function can not be called statically.
HTML_QuickForm::defaultRenderer()
HTML_QuickForm::defaultRenderer() – Returns a reference to default renderer object
Synopsis
require_once 'HTML/QuickForm.php';
object &HTML_QuickForm::defaultRenderer (
void
)
Description
Returns a reference to default renderer object. You can use this method to save a few keystrokes:
<?php
$renderer =& $form->defaultRenderer();
?>instead of
<?php
require_once 'HTML/QuickForm/Renderer/Default.php';
$renderer =& new HTML_QuickForm_Renderer_Default();
?>It is also used internally to implement toHtml() and some of the deprecated methods.
Return value
return default renderer object
Throws
throws no exceptions thrown
Note
since 3.0
This function can be called statically.
HTML_QuickForm::toArray()
HTML_QuickForm::toArray() – Returns the form's contents in an array
Synopsis
require_once 'HTML/QuickForm.php';
array HTML_QuickForm::toArray (
boolean $collectHidden
= false
)
Description
Returns the form's contents in an array, uses Array renderer for this.
Parameter
-
boolean
$collectHidden -
Whether to collect hidden elements (passed to the Renderer's constructor)
Return value
return array of form contents, structure is described in renderer documentation.
Throws
throws no exceptions thrown
Note
since 2.0
This function can not be called statically.
HTML_QuickForm::toHtml()
HTML_QuickForm::toHtml() – Returns an HTML version of the form
Synopsis
require_once 'HTML/QuickForm.php';
string HTML_QuickForm::toHtml (
string $in_data
= null
)
Description
Returns an HTML version of the form, uses Default renderer for this.
Parameter
-
string
$in_data -
(optional) Any extra data to insert right before form is rendered. Data will be inserted via addElement('html', $in_data)
Return value
return Html version of the form
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
HTML_QuickForm::display()
HTML_QuickForm::display() – Outputs an HTML version of the form
Synopsis
require_once 'HTML/QuickForm.php';
string HTML_QuickForm::display (
)
Description
Outputs an HTML version of the form, uses Default renderer for this.
Throws
throws no exceptions thrown
Note
since 1.0
This function can not be called statically.
Basic renderers
These renderers are based on pre-3.0 HTML_QuickForm code and require no external classes to do their work.
Introduction - renderers
Introduction - renderers – How to output the form
What are renderers?
Before release 3.0, form outputting logic was implemented as methods of HTML_QuickForm class. This led to two problems:
- Bloat of the said class (80+ methods!)
- Difficulties in adding new output logic (i.e. using template engines)
In release 3.0, new system was implemented. The form output logic is now contained in classes that extend HTML_QuickForm_Renderer, their behaviour is based on Visitor design pattern from the classic "Design Patterns" book. This gives the following advantages:
- Code for some particular output method is loaded only when the method is used.
- It is much easier to add new output method.
There are 8 renderers available since release 3.1.1, of which 2 are based on pre-3.0 code and 6 are new. The following template engines are directly suported: Smarty, HTML_Template_Sigma, HTML_Template_IT, HTML_Template_Flexy.
The main steps of using any available renderer are quite similar:
<?php
// include the renderer class
require_once 'HTML/QuickForm/Renderer/FooBar.php';
// instantiate the renderer
$renderer =& new HTML_QuickForm_Renderer_FooBar($options);
// do some customization
$renderer->adjustSomething('element1', '...');
// ...
$renderer->adjustSomething('elementN', '...');
// process the form
$form->accept($renderer);
// output the results
$renderer->toFooBar();
?>Actual methods for customization and doing the output will of course depend on renderer type.
Concerning usage examples
Usage examples provided in the manual are pretty basic. More complex examples for Default renderer can be found in
docs/directory, for all other renderers - indocs/renderers/directory of HTML_QuickForm.
HTML_QuickForm_Renderer_Default
HTML_QuickForm_Renderer_Default – Default renderer
Description
This renderer directly generates and outputs form HTML. It is based on pre-3.0 built-in form output logic.
The renderer has built-in templates for elements, their format is similar to that of HTML_Template_Sigma or HTML_Template_IT (but only placeholders and blocks are supported). When renderer's renderSomething() method is called, it finds the template for the element, makes necessary substitutions and appends the result to the form's HTML.
Usage example
It is recommended to use the Default renderer when you are not using any template engine in your application or do not need to do any customization to form output. It is the fastest way to output a form.
Default renderer usage
<?php
require_once 'HTML/QuickForm/Renderer/Default.php';
$renderer =& new HTML_QuickForm_Renderer_Default();
$form->accept($renderer);
echo $renderer->toHtml();
?>
HTML_QuickForm::toHtml() method uses the Default renderer internally.
HTML_QuickForm_Renderer_Default::clearAllTemplates()
HTML_QuickForm_Renderer_Default::clearAllTemplates() – Clears all templates
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
void HTML_QuickForm_Renderer_Default::clearAllTemplates (
void
)
Description
Clears all the HTML out of the templates that surround notes, elements, etc.
Useful when you want to use addElement('html', '...') to create a completely custom form look.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Default::setElementTemplate()
HTML_QuickForm_Renderer_Default::setElementTemplate() – Sets element template
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
void HTML_QuickForm_Renderer_Default::setElementTemplate (
string $html
, string $element
= null
)
Description
Sets element template. When called with one parameter, it sets the default element template, when
called with two parameters it sets template for the concrete element. The template should include
at least the {element} placeholder.
The default element template is
"\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required --><b>{label}</b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>"
Parameter
-
string
$html -
The HTML surrounding an element
-
string
$element -
(optional) Name of the element to apply template for
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Default::setFormTemplate()
HTML_QuickForm_Renderer_Default::setFormTemplate() – Sets form template
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
void HTML_QuickForm_Renderer_Default::setFormTemplate (
string $html
)
Description
Sets form template. The template should include {attributes} and {content} placeholders.
The default form template is
"\n<form{attributes}>\n<table border=\"0\">\n{content}\n</table>\n</form>"
Parameter
-
string
$html -
The HTML surrounding the form tags
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Default::setGroupElementTemplate()
HTML_QuickForm_Renderer_Default::setGroupElementTemplate() – Sets template for group elements
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
void HTML_QuickForm_Renderer_Default::setGroupElementTemplate (
string $html
, string $group
)
Description
Sets element template for elements within a group.
By default, the template is empty.
Parameter
-
string
$html -
The HTML surrounding an element
-
string
$group -
Name of the group to apply template for
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Default::setGroupTemplate()
HTML_QuickForm_Renderer_Default::setGroupTemplate() – Sets template for a group wrapper
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
void HTML_QuickForm_Renderer_Default::setGroupTemplate (
string $html
, string $group
)
Description
Sets template for a group wrapper
This template is contained within a group-as-element template set via setElementTemplate() and contains group's element templates, set via setGroupElementTemplate().
By default, the template is empty.
Parameter
-
string
$html -
The HTML surrounding group elements
-
string
$group -
Name of the group to apply template for
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Default::setHeaderTemplate()
HTML_QuickForm_Renderer_Default::setHeaderTemplate() – Sets header template
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
void HTML_QuickForm_Renderer_Default::setHeaderTemplate (
string $html
)
Description
Sets header template. The template should include the {header} placeholder.
The default header template is
"\n\t<tr>\n\t\t<td style=\"white-space: nowrap; background-color: #CCCCCC;\" align=\"left\" valign=\"top\" colspan=\"2\"><b>{header}</b></td>\n\t</tr>"
Parameter
-
string
$html -
The HTML surrounding the header
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Default::setRequiredNoteTemplate()
HTML_QuickForm_Renderer_Default::setRequiredNoteTemplate() – Sets the template for 'required' note
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
void HTML_QuickForm_Renderer_Default::setRequiredNoteTemplate (
string $html
)
Description
Sets the note indicating required fields template. The template should include the {requiredNote} placeholder.
The default template is
"\n\t<tr>\n\t\t<td></td>\n\t<td align=\"left\" valign=\"top\">{requiredNote}</td>\n\t</tr>"
Parameter
-
string
$html -
The HTML surrounding the required note
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Default::toHtml()
HTML_QuickForm_Renderer_Default::toHtml() – Returns the HTML
Synopsis
require_once 'HTML/QuickForm/Renderer/Default.php';
string HTML_QuickForm_Renderer_Default::toHtml (
void
)
Description
Returns the HTML generated for the form.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Array
HTML_QuickForm_Renderer_Array – Array representation of the form
Description
This renderer does not output anything itself, it returns the form structure as an
array. This array can later be used for generating the output. A usage example is
available for this renderer and Smarty template engine, look in
docs/renderers directory.
The form array structure is the following:
array(
'frozen' => 'whether the form is frozen',
'javascript' => 'javascript for client-side validation',
'attributes' => 'attributes for <form> tag',
'requirednote => 'note about the required elements',
// if we set the option to collect hidden elements
'hidden' => 'collected html of all hidden elements',
// if there were some validation errors:
'errors' => array(
'1st element name' => 'Error for the 1st element',
...
'nth element name' => 'Error for the nth element'
),
// if there are no headers in the form:
'elements' => array(
element_1,
...
element_N
)
// if there are headers in the form:
'sections' => array(
array(
'header' => 'Header text for the first header',
'name' => 'Name of the first header',
'elements' => array(
element_1,
...
element_K1
)
),
...
array(
'header' => 'Header text for the Mth header',
'elements' => array(
element_1,
...
element_KM
)
)
)
);
where element_i is an array of the form:
array(
'name' => 'element name',
'value' => 'element value',
'type' => 'type of the element',
'frozen' => 'whether element is frozen',
'label' => 'label for the element',
'required' => 'whether element is required',
'error' => 'error associated with the element',
'style' => 'some information about element style (e.g. for Smarty)',
// if element is not a group
'html' => 'HTML for the element'
// if element is a group
'separator' => 'separator for group elements',
'elements' => array(
element_1,
...
element_N
)
);
HTML_QuickForm::toArray() method uses the Array renderer internally.
constructor HTML_QuickForm_Renderer_Array::HTML_QuickForm_Renderer_Array()
constructor HTML_QuickForm_Renderer_Array::HTML_QuickForm_Renderer_Array() – Constructor
Synopsis
require_once 'HTML/QuickForm/Renderer/Array.php';
void HTML_QuickForm_Renderer_Array::HTML_QuickForm_Renderer_Array (
bool $collectHidden
= false
bool $staticLabels
= false
)
Description
This package is not documented yet.
Parameter
-
boolean
$collectHidden -
TRUE: collect all hidden elements into string; FALSE: process them as usual form elements
- boolean
$staticLabels -
TRUE: instead of putting an array of labels into the
'label'element of resultant array, create separate keys for them named'label_$key'where $key is the key in the array of labels (key + 1 if it is numeric). The first element of the array occupies the'label'element.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Array::setElementStyle()
HTML_QuickForm_Renderer_Array::setElementStyle() – Sets a style to use for element rendering
Synopsis
require_once 'HTML/QuickForm/Renderer/Array.php';
void HTML_QuickForm_Renderer_Array::setElementStyle (
mixed $elementName
, string $styleName
= null
)
Description
Sets a style to use for element rendering (this style can later be checked by e.g. a template engine).
Parameter
-
mixed
$elementName -
element name or array ('element name' => 'style name')
-
string
$styleName -
style name if
$elementNameis not an array
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Array::toArray()
HTML_QuickForm_Renderer_Array::toArray() – Returns the resultant array
Synopsis
require_once 'HTML/QuickForm/Renderer/Array.php';
array HTML_QuickForm_Renderer_Array::toArray (
void
)
Description
Returns an array representation of the form built by the renderer.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Object
HTML_QuickForm_Renderer_Object – Object representation of the form
Description
This renderer does not output anything itself, it returns the form structure as an
object. This object can later be used for generating the output. A usage example is
available for this renderer and the Flexy template engine, look in
docs/renderers directory.
The form object structure is similar to the following:
QuickformForm Object
(
[frozen] =>
[javascript] =>
[attributes] => action="/object.php" method="post" name="form" id="form"
[requirednote] => <span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;"> denotes required field</span>
[hidden] =>
[errors] => stdClass Object
(
)
[elements] => Array
(
[0] => QuickformElement Object
(
[name] => session
[value] => 1234567890
[type] => hidden
[frozen] =>
[label] =>
[required] =>
[error] =>
[style] =>
[html] => <input name="session" type="hidden" value="1234567890" />
[separator] =>
[elements] =>
)
...
)
[sections] => Array
(
[0] => stdClass Object
(
[header] => Personal Information
[elements] => Array
(
[0] => QuickformElement Object
(
[name] => email
[value] =>
[type] => text
[frozen] =>
[label] => Your email:
[required] => 1
[error] =>
[style] =>
[html] => <input name="email" type="text" />
[separator] =>
[elements] =>
)
...
)
)
...
)
)
HTML_QuickForm::toObject() method uses the object renderer internally.
constructor HTML_QuickForm_Renderer_Object::HTML_QuickForm_Renderer_Object()
constructor HTML_QuickForm_Renderer_Object::HTML_QuickForm_Renderer_Object() – Constructor
Synopsis
require_once 'HTML/QuickForm/Renderer/Object.php';
void HTML_QuickForm_Renderer_Object::HTML_QuickForm_Renderer_Object (
bool $collectHidden
= false
)
Description
This package is not documented yet.
Parameter
-
boolean
$collectHidden -
TRUE: collect all hidden elements into string; FALSE: process them as usual form elements
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_Object::toObject()
HTML_QuickForm_Renderer_Object::toObject() – Returns the resultant object
Synopsis
require_once 'HTML/QuickForm/Renderer/Object.php';
QuickformForm HTML_QuickForm_Renderer_Object::toObject (
void
)
Description
Returns an object representation of the form built by the renderer.
Throws
throws no exceptions thrown
Note
This function can not be called statically.
Template-based renderers
These renderers use template engines to actually generate the HTML for the form.
HTML_QuickForm_Renderer_ArraySmarty
HTML_QuickForm_Renderer_ArraySmarty – A renderer for 'static' Smarty templates
Description
This renderer was written by Thomas Schulz. It is based on pre-3.0
HTML_QuickForm::toArray() code and ITStatic renderer. It can be used to
output the form into the 'static' Smarty template. Usage example for this is available in
docs/renderers.
The form array structure is the following:
array (
['frozen'] => 'whether the complete form is frozen',
['javascript'] => 'javascript for client-side validation',
['attributes'] => 'attributes for <form> tag',
['hidden'] => 'html of all hidden elements',
['requirednote'] => 'note about the required elements',
['errors'] => Array
(
['1st_element_name'] => 'Error for the 1st element',
...
['nth_element_name'] => 'Error for the nth element',
),
['header'] => Array
(
['1st_header_name'] => 'Header text for the 1st header',
...
['nth_header_name'] => 'Header text for the nth header'
),
['1st_element_name'] => 'Array for the 1st element',
...
['nth_element_name'] => Array for the nth element'
);
where an element array has the form:
array(
['name'] => 'element name',
['value'] => 'element value',
['type'] => 'type of the element',
['frozen'] => 'whether element is frozen',
['label'] => 'label for the element',
['required'] => 'whether element is required',
// if element is not a group:
['html'] => 'HTML for the element',
// if element is a group:
['separator'] => 'separator for group elements',
['1st_gitem_name'] => 'Array for the 1st element in group',
...
['nth_gitem_name'] => 'Array for the nth element in group'
);
constructor HTML_QuickForm_Renderer_ArraySmarty::HTML_QuickForm_Renderer_ArraySmarty()
constructor HTML_QuickForm_Renderer_ArraySmarty::HTML_QuickForm_Renderer_ArraySmarty() – Constructor
Synopsis
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
void HTML_QuickForm_Renderer_ArraySmarty::HTML_QuickForm_Renderer_ArraySmarty (
mixed &$tpl
)
Description
This package is not documented yet.
Parameter
-
object
&$tpl -
A Smarty object to use for form output
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ArraySmarty::setErrorTemplate()
HTML_QuickForm_Renderer_ArraySmarty::setErrorTemplate() – Sets the way elements with validation errors are rendered
Synopsis
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
void HTML_QuickForm_Renderer_ArraySmarty::setErrorTemplate (
string $template
)
Description
You can use {$label} or {$html} placeholders to let the renderer know where where the element label or the element html are positionned according to the error message. They will be replaced accordingly with the right value. The error message will replace the {$error} placeholder. For example: {if $error}<span style="color: red;">{$error}</span>{/if}{$html} will put the error message in red on top of the element html.
If you want all error messages to be output in the main error block, use the {$form.errors} part of the rendered array that collects all raw error messages.
If you want to place all error messages manually, do not specify {$html} nor {$label}.
Groups can have special layouts. With this kind of groups, you have to place the formated error message manually. In this case, use {$form.group.error} where you want the formated error message to appear in the form.
Parameter
-
string
$template -
The element error template
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ArraySmarty::setRequiredTemplate()
HTML_QuickForm_Renderer_ArraySmarty::setRequiredTemplate() – Sets the way required elements are rendered
Synopsis
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
void HTML_QuickForm_Renderer_ArraySmarty::setRequiredTemplate (
string $template
)
Description
You can use {$label} or {$html} placeholders to let the renderer know where where the element label or the element html are positionned according to the required tag. They will be replaced accordingly with the right value. You can use the full smarty syntax here, especially a custom modifier for I18N. For example: {if $required}<span style="color: red;">*</span>{/if}{$label|translate} will put a red star in front of the label if the element is required and translate the label.
Parameter
-
string
$template -
The required element template
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ITDynamic
HTML_QuickForm_Renderer_ITDynamic – Dynamic renderer for Integrated Templates
Description
The word 'dynamic' in renderer name means that exact form layout is defined at script runtime. This also means that you can create one template file for all your forms. That template should contain a block for every distinct element 'look' appearing in your forms and also some special blocks. If a special block is not set for an element, the renderer falls back to a default one.
If most of your forms tend to share the same look (a good example would be back-office interface), your best bet will be to use Dynamic renderer. If each of your forms has a really special layout, you should go with a Static one.
Template structure
This is a somewhat minimal template, but it contains all the necessary elements to render any form you are able to define with the package.
{qf_javascript}
<form {qf_attributes}>
<!-- BEGIN qf_hidden_loop -->
{qf_hidden}
<!-- END qf_hidden_loop -->
<table>
<!-- BEGIN qf_errors -->
<tr>
<td>
Collected errors:
<ul>
<!-- BEGIN qf_error_loop -->
<li>{qf_error}</li>
<!-- END qf_error_loop -->
</ul>
</td>
</tr>
<!-- END qf_errors -->
<!-- BEGIN qf_main_loop -->
<!-- BEGIN qf_header -->
<tr>
<th colspan="2">{qf_header}</th>
</tr>
<!-- END qf_header -->
<!-- BEGIN qf_element -->
<tr valign="top">
<td align="right">
<!-- BEGIN qf_element_required --><span style="color: #FF0000;">*</span><!-- END qf_element_required -->
<b>{qf_label}</b>
</td>
<td>
<!-- BEGIN qf_element_error --><span style="color: #FF0000;">{qf_error}</span><br /><!-- END qf_element_error -->
{qf_element}
</td>
</tr>
<!-- END qf_element -->
<!-- BEGIN qf_group -->
<tr valign="top">
<td align="right">
<!-- BEGIN qf_group_required --><span style="color: #FF0000;">*</span><!-- END qf_group_required -->
<b>{qf_group_label}</b>
</td>
<td>
<!-- BEGIN qf_group_error --><span style="color: #FF0000;">{qf_error}</span><br /><!-- END qf_group_error -->
<!-- BEGIN qf_group_loop -->
<!-- BEGIN qf_group_element -->{qf_separator}{qf_label}{qf_element}<!-- END qf_group_element -->
<!-- END qf_group_loop -->
</td>
</tr>
<!-- END qf_group -->
<!-- END qf_main_loop -->
<!-- BEGIN qf_required_note -->
<tr>
<td> </td>
<td align="left" valign="top">{qf_required_note}</td>
</tr>
<!-- END qf_required_note -->
</table>
</form>
qf_main_loopThis block should always be present and should be a parent for all visible elements' blocks. It is used to implement "flow", to render elements one after another.
qf_elementThis is the default block for rendering form elements. This block should always be present, as the renderer uses the following logic to decide which block to use for an element's output:
- If a special block was set for an element, use that
- If a block
qf_%element's type%(e.g.qf_password) exists, use that - Use
qf_element
qf_element_requiredThe block will be touch'd if an element is required.
qf_element_errorAn error associated with an element will be output here.
qf_headerThis is the default block used to output headers. Should be present unless you have no headers in your form.
qf_groupDefault block to output groups. Should be present unless you do not use grouped elements.
qf_group_loopAn analog of
qf_main_loop, used to render group's elements one after another. A%group's block%_loopshould always be present inside%group's block%
qf_group_elementA default block to render group's elements,
%group's block%_elementshould always be present inside%group's block%_loop(for the same reason as theqf_elementshould be present inqf_main_loop)
qf_error_loopThis is used to output collected errors for the elements that do not have a
%element's block%_errorblock.
qf_hidden_loop<input type="hidden" /> elements are rendered here.
{qf_javascript}Javascript for client-side form validation will be output here.
{qf_required_note}If there are required elements in the form, a note will be output here
Usage example
Assuming the template is in ./qform.html:
<?php
require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
require_once 'HTML/Template/Sigma.php';
// Instantiate the template object and load the template file
$tpl =& new HTML_Template_Sigma('.');
$tpl->loadTemplateFile('qform.html');
// Instantiate the renderer and process the form
$renderer =& new HTML_QuickForm_Renderer_ITDynamic($tpl);
$form->accept($renderer);
// Output the results
$tpl->show();
?>Note that we do not show how the form is built here, that's because the example will work for virtually any form.
Template class compatibility
This renderer was developed and tested using HTML_Template_Sigma. While it probably will work with HTML_Template_IT, no warranties can be given.
Removing empty blocks
The renderer assumes that the template object was set up to remove empty blocks (this is the default behaviour). If that is not true, the results will be pretty discouraging.
constructor HTML_QuickForm_Renderer_ITDynamic::HTML_QuickForm_Renderer_ITDynamic()
constructor HTML_QuickForm_Renderer_ITDynamic::HTML_QuickForm_Renderer_ITDynamic() – Constructor
Synopsis
require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
void HTML_QuickForm_Renderer_ITDynamic::HTML_QuickForm_Renderer_ITDynamic (
object &$tpl
)
Description
This package is not documented yet.
Parameter
-
object
&$tpl -
HTML_Template_ITX/HTML_Template_Sigma object to use
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ITDynamic::setElementBlock()
HTML_QuickForm_Renderer_ITDynamic::setElementBlock() – Sets the block to use for element rendering
Synopsis
require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
void HTML_QuickForm_Renderer_ITDynamic::setElementBlock (
mixed $elementName
, string $blockName
= null
)
Description
Sets the block to use for element rendering.
Parameter
-
mixed
$elementName -
element name or array ('element name' => 'block name')
-
string
$blockName -
block name if
$elementNameis not an array
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ITDynamic::setHeaderBlock()
HTML_QuickForm_Renderer_ITDynamic::setHeaderBlock() – Sets the name of a block to use for header rendering
Synopsis
require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
void HTML_QuickForm_Renderer_ITDynamic::setHeaderBlock (
string $blockName
)
Description
Sets the name of a block to use for header rendering
Parameter
-
string
$blockName -
block name
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ITStatic
HTML_QuickForm_Renderer_ITStatic – Static renderer for Integrated Templates
Description
The word 'static' in renderer name means that exact form layout is defined before the execution of the script starts. That also means that you should have an unique template for each form you want to display with this renderer.
The IT Static renderer, as opposed to the IT Dynamic renderer, offers more flexibility in the way you display your forms but might also takes more time to implement. Therefore, if your form is using always the same pattern to display form element labels and form element html, it is recommended to use the Dynamic renderer. On the other hand, if you have many different layouts for your form elements, for example if you alternate text and form elements, you will prefer to use the Static renderer.
Usage example
With the ITStatic renderer, you have to know beforehand which elements (or group of elements) will compose your form. So we will start by defining our elements.
Defining the elements
<?php
require_once ("HTML/QuickForm.php");
$form = new HTML_QuickForm('myform', 'POST');
$form->addElement('header', 'myheader', 'Registration form');
$form->addElement('hidden', 'session', '123456');
$name['last'] = &HTML_QuickForm::createElement('text', 'first', 'First', array('size' => 10));
$name['first'] = &HTML_QuickForm::createElement('text', 'last', 'Last', array('size' => 10));
$form->addGroup($name, 'name', 'Name:', '-');
$form->addElement('text', 'email', 'Your email:');
$select = array('' => 'Please select...',
'AU' => 'Australia',
'FR' => 'France',
'DE' => 'Germany',
'IT' => 'Italy');
$form->addElement('select', 'country', 'Country:', $select);
$form->addElement('reset', 'reset', 'Reset');
$form->addElement('submit', 'submit', 'Register');
$form->addElement('checkbox', 'news', '', " Check this box if you don't want to receive our newsletter.");
?>
Now our form contains these elements:
- One header: 'Registration form'
- One hidden field
- One group of two textfields: firstname and lastname
- One textfield for the E-Mail address
- One selectbox for the country with an empty default value
- Two buttons: Reset and Register
- One checkbox to subscribe to the newsletter
Now that we know which elements compose our form, it will be easy to layout the form
using a WYSIWYG or an HTML editor. The idea is to use placeholders instead of labels
and element html. The placeholders are named after the form and element or group
names: formName_elementName or formName_groupName_elementName. Then
you add _label or _html. We will save the following code in a
template.html file.
A template
<html>
<head><title>My Form</title>
{myform_javascript}
</head>
<body>
<form {myform_attributes}>
{myform_session_html}
<table>
<tr><th colspan="2">{myform_myheader}</th></tr>
<tr><td>{myform_name_label}</td><td>{myform_name_html}</td></tr>
<tr><td>{myform_email_label}</td><td>{myform_email_html}</td></tr>
<tr><td>{myform_country_label}</td><td>{myform_country_html}</td></tr>
<tr><td colspan="2" align="right">{myform_reset_html} {myform_submit_html}</td></tr>
</table>
<br /><br />
{myform_news_html}
</form>
</body>
</html>
As you can notice, the layout is static. This makes the Static renderer only useful if
your form does not change on runtime. Nevertheless, you can still hide blocks if you
use the removeEmptyBlocks option of
HTML_Template_IT /
HTML_Template_Sigma.
Now that we have the elements and the template, we are going to use our Static renderer.
Using the renderer
<?php
require_once 'HTML/Template/Sigma.php';
require_once 'HTML/QuickForm/Renderer/ITStatic.php';
$tpl =& new HTML_Template_Sigma('.');
$tpl->loadTemplateFile('template.html'); // or whatever you called it
$renderer =& new HTML_QuickForm_Renderer_ITStatic($tpl);
$renderer->setRequiredTemplate('{label}<font color="red" size="1">*</font>');
$renderer->setErrorTemplate('<font color="red">{error}</font><br />{html}');
$form->accept($renderer);
$tpl->show();
?>
You can optionally specify the way your required elements and validation errors are
rendered using respectively setRequiredTemplate() and
setErrorTemplate(). In the given string, you will place either the
{label} or the {html} placeholder at
the position you want. If you prefer to have all your errors displayed at the same
place, pass an empty string to setErrorTemplate() and add this
block to your template at the position you want:
<!-- BEGIN myform_error_loop -->
<font color="red">{myform_error}</font><br />
<!-- END myform_error_loop -->
With the Static renderer, it is also possible to customize the way your groups are rendered. If you simply use a placeholder for your whole group, the group will be rendered using HTML_QuickForm default renderer. This means that if a separator string (or an array of separators) was specified, it will be used the usual way. In our form, the group called 'name' was rendered this way, using a - to separate the elements.
The problem we have is that elements inside the group don't show their label, so it is not possible to guess which textfield is firstname and which one is lastname. By replacing the layout for the element 'name' by these new placeholders, can customize the way the group will be displayed:
(...)
<tr>
<td>{myform_name_label}</td>
<td>
<!-- BEGIN myform_name_error -->{myform_name_error}<!-- END myform_name_error -->
<table>
<tr><td>{myform_name_first_html}</td><td>{myform_name_last_html}</td></tr>
<tr><td>{myform_name_first_label}</td><td>{myform_name_last_label}</td></tr>
</table>
</td>
</tr>
(...)
We need to add a new block and placeholder to let the renderer know where to display the error relative to this group. As you have noticed, every placeholder take the name of his group along with its own name.
Also note that if you use elements with the same name, like radios that are not in a group, you will have to add an index to the placeholder name starting at 0, like this:
{myform_myradio_0_html},{myform_myradio_1_html}...
We have seen how to use the Static renderer with standard elements and groups of
elements. We have seen how to display errors and required tags. They won't show in your
form because we did not add any validation rules. Feel free to try to add them as an
exercise. You can also add a special placeholder to your template
{myform_required_note}, it will display the note that indicates
how to find required elements. This renderer usage is very easy, when you feel
comfortable with it, you can move on to the Dynamic renderer which might also fit your
needs in an other way.
constructor HTML_QuickForm_Renderer_ITStatic::HTML_QuickForm_Renderer_ITStatic()
constructor HTML_QuickForm_Renderer_ITStatic::HTML_QuickForm_Renderer_ITStatic() – Constructor
Synopsis
require_once 'HTML/QuickForm/Renderer/ITStatic.php';
void HTML_QuickForm_Renderer_ITStatic::HTML_QuickForm_Renderer_ITStatic (
object &$tpl
)
Description
This package is not documented yet.
Parameter
-
object
&$tpl -
HTML_Template_IT or other compatible Template object to use
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ITStatic::setErrorTemplate()
HTML_QuickForm_Renderer_ITStatic::setErrorTemplate() – Sets the way elements with validation errors are rendered
Synopsis
require_once 'HTML/QuickForm/Renderer/ITStatic.php';
void HTML_QuickForm_Renderer_ITStatic::setErrorTemplate (
string $template
)
Description
You can use {label} or {html} placeholders to let the renderer know where where the element label or the element html are positionned according to the error message. They will be replaced accordingly with the right value. The error message will replace the {error} place holder. For example: <font color="red">{error}</font>{html} will put the error message in red on top of the element html.
If you want all error messages to be output in the main error block, do not specify {html} nor {label}.
Groups can have special layouts. With this kind of groups, the renderer will need to know where to place the error message. In this case, use error blocks like: <!-- BEGIN form_group_error -->{form_group_error}<!-- END form_group_error --> where you want the error message to appear in the form.
Parameter
-
string
$template -
The element error template
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ITStatic::setRequiredTemplate()
HTML_QuickForm_Renderer_ITStatic::setRequiredTemplate() – Sets the way required elements are rendered
Synopsis
require_once 'HTML/QuickForm/Renderer/ITStatic.php';
void HTML_QuickForm_Renderer_ITStatic::setRequiredTemplate (
string $template
)
Description
You can use {label} or {html} placeholders to let the renderer know where where the element label or the element html are positionned according to the required tag. They will be replaced accordingly with the right value. For example: <font color="red">*</font>{label} will put a red star in front of the label if the element is required.
Parameter
-
string
$template -
The required element template
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ObjectFlexy
HTML_QuickForm_Renderer_ObjectFlexy – A renderer for Flexy templates
Description
This renderer allows you to output your form using a Flexy template.
A static and dynamic usage example is available in the
docs/renderers directory.
Usage example
The following is an example of using the ObjectFlexy renderer with a simple template.
Defining the elements
<?php
require_once 'HTML/Template/Flexy.php';
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/ObjectFlexy.php';
// Form name will be used to find the placeholders.
$form = new HTML_QuickForm('form', 'POST');
// Personal information
$form->addElement('header', 'personal', 'Personal Information');
$form->addElement('text', 'email', 'Your email:');
$form->addElement('password', 'pass', 'Your password:', 'size=10');
$name['last'] = &HTML_QuickForm::createElement('text', 'first', 'First', 'size=10');
$name['first'] = &HTML_QuickForm::createElement('text', 'last', 'Last', 'size=10');
$form->addGroup($name, 'name', 'Name:', ', ');
$areaCode = &HTML_QuickForm::createElement('text', '', null,'size=4 maxlength=3');
$phoneNo1 = &HTML_QuickForm::createElement('text', '', null, 'size=4 maxlength=3');
$phoneNo2 = &HTML_QuickForm::createElement('text', '', null, 'size=5 maxlength=4');
$form->addGroup(array($areaCode, $phoneNo1, $phoneNo2), 'phone', 'Telephone:', '-');
// Company information
$form->addElement('header', 'company_info', 'Company Information');
$form->addElement('text', 'company', 'Company:', 'size=20');
$str[] = &HTML_QuickForm::createElement('text', '', null, 'size=20');
$str[] = &HTML_QuickForm::createElement('text', '', null, 'size=20');
$form->addGroup($str, 'street', 'Street:', '<br />');
$addr['zip'] = &HTML_QuickForm::createElement('text', 'zip', 'Zip', 'size=6 maxlength=10');
$addr['city'] = &HTML_QuickForm::createElement('text', 'city', 'City', 'size=15');
$form->addGroup($addr, 'address', 'Zip, city:');
$select = array('' => 'Please select...', 'AU' => 'Australia', 'FR' => 'France', 'DE' => 'Germany', 'IT' => 'Italy');
$form->addElement('select', 'country', 'Country:', $select);
// Other elements
$form->addElement('checkbox', 'news', '', " Check this box if you don't want to receive our newsletter.");
$form->addElement('reset', 'reset', 'Reset');
$form->addElement('submit', 'submit', 'Register');
// Tries to validate the form
if ($form->validate()) {
// Form is validated, then freezes the data
$form->freeze();
}
// setup a template object
$options = &PEAR::getStaticProperty('HTML_Template_Flexy','options');
$options = array(
'templateDir' => './templates',
'compileDir' => './templates/build',
'forceCompile' => 1,
'debug' => 0,
'local' => 'en'
);
$template = new HTML_Template_Flexy($options);
$renderer =& new HTML_QuickForm_Renderer_ObjectFlexy($template);
$renderer->setLabelTemplate("label.html");
$renderer->setHtmlTemplate("html.html");
$form->accept($renderer);
$view = new StdClass;
$view->form = $renderer->toObject();
$template->compile("flexy-static.html");
$template->outputObject($view);
?>
The template files used above are the following:
label.html
A template for the labels
{if:required}
<font color="red" size="1">*</font>
{end:}
{label:h}
html.html
A template for the overall html
{if:error}
<font color="orange" size="1">{error:h}</font><br />
{end:}
{html:h}
flexy-static.html
A template for the form
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- $Id: html-quickform-renderer-objectflexy.xml,v 1.3 2008-10-09 15:16:33 cweiske Exp $ -->
<html>
<head>
<title>Flexy template : 2 column layout example</title>
<style type="text/css">
.errors {
font-family: sans-serif;
color : #000;
background-color : #FFF;
font-size : 12pt;
}
.label {
font-family: sans-serif;
color : Navy;
font-size : 11px;
text-align : right;
vertical-align : top;
white-space: nowrap;
}
.element {
font-family: sans-serif;
background-color : #EEE;
text-align : left;
white-space: nowrap;
}
.note {
font-family: sans-serif;
background-color : #EEE;
text-align : center;
font-size : 10pt;
color : AAA;
white-space: nowrap;
}
th {
font-family: sans-serif;
font-size : small;
color : #FFF;
background-color : #AAA;
}
.maintable {
border : thin dashed #D0D0D0;
background-color : #EEE;
}
</style>
{form.javascript:h}
</head>
<body>
{form.outputHeader():h}
{form.hidden:h}
<table class="maintable" width="600" align="center">
<tr>
<td width="50%" valign="top"><!-- Personal info -->
<table width="100%" cellpadding="4">
<tr><th colspan="2">{form.header.personal:h}</th></tr>
<tr>
<td class="label">{form.name.label:h}</td>
<td class="element">{form.name.error:h}
<table cellspacing="0" cellpadding="1">
<tr>
<td>{form.name.first.html:h}</td>
<td>{form.name.last.html:h}</td>
</tr>
<tr>
<td><font size="1" color="grey">{form.name.first.label:h}</font></td>
<td><font size="1" color="grey">{form.name.last.label:h}</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="label">{form.phone.label:h}</td>
<td class="element">{form.phone.html:h}</td>
</tr>
<tr>
<td class="label">{form.email.label:h}</td>
<td class="element">{form.email.html:h}</td>
</tr>
<tr><td colspan="2" class="note">Please, choose a 8-10 characters password.</td></tr>
<tr>
<td class="label">{form.pass.label:h}</td>
<td class="element">{form.pass.html:h}</td>
</tr>
</table>
</td>
<td width="50%" valign="top"><!-- Company info -->
<table width="100%" cellpadding="4">
<tr><th colspan="2">{form.header.company_info:h}</th></tr>
<tr>
<td class="label">{form.company.label:h}</td>
<td class="element">{form.company.html:h}</td>
</tr>
<tr>
<td class="label" valign="top">{form.street.label:h}</td>
<td class="element">{form.street.html:h}</td>
</tr>
<tr>
<td class="label">{form.address.label:h}</td>
<td class="element">{form.address.error:h}
<table cellspacing="0" cellpadding="1">
<tr>
<td>{form.address.zip.html:h}</td>
<td>{form.address.city.html:h}</td>
</tr>
<tr>
<td><font size="1" color="grey">{form.address.zip.label:h}</font></td>
<td><font size="1" color="grey">{form.address.city.label:h}</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="label">{form.country.label:h}</td>
<td class="element">{form.country.html:h}</td>
</tr>
<tr>
<td class="label">{form.destination.label:h}</td>
<td class="element">{form.destination.html:h}</td>
</tr>
</table>
</td>
</tr>
</table>
<table width="600" align="center">
<tr>
<td>{form.requirednote:h}</td>
<td align="right">{form.reset.html:h} {form.submit.html:h}</td>
</tr>
<tr>
<td colspan="2" style="font-size:11px; color: navy;"><br />{form.news.html:h}</td>
</tr>
</table>
</form>
<br />
<b>Collected Errors:</b><br />
{foreach:form.errors,error}
<font color="red">{error}</font> in element [{name}]<br />
{end:}
<p><strong>The used "Static" Object</strong></p>
<pre style="font-size: 12px;">
{static_object}
</pre>
</body>
</html>
For more information on Flexy templating, see the package homepage.
constructor HTML_QuickForm_Renderer_ObjectFlexy::HTML_QuickForm_Renderer_ObjectFlexy()
constructor HTML_QuickForm_Renderer_ObjectFlexy::HTML_QuickForm_Renderer_ObjectFlexy() – Constructor
Synopsis
require_once 'HTML/QuickForm/Renderer/ObjectFlexy.php';
void HTML_QuickForm_Renderer_ObjectFlexy::HTML_QuickForm_Renderer_ObjectFlexy (
object &$flexy
)
Description
This package is not documented yet.
Parameter
-
object
&$flexy -
HTML_Template_Flexy or other compatible Template object to use
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ObjectFlexy::setHtmlTemplate()
HTML_QuickForm_Renderer_ObjectFlexy::setHtmlTemplate() – Set the filename of the template to render html elements.
Synopsis
require_once 'HTML/QuickForm/Renderer/ObjectFlexy.php';
void HTML_QuickForm_Renderer_ObjectFlexy::setHtmlTemplate (
string $template
)
Description
In your template, {html} is replaced by the unmodified html. If the element is required, {required} will be true. Eg.
{if:error}
<font color="red" size="1">{error:h}</font><br />
{end:}
{html:h}
Parameter
-
string
$template -
Filename of template
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_ObjectFlexy::setLabelTemplate()
HTML_QuickForm_Renderer_ObjectFlexy::setLabelTemplate() – Set the filename of the template to render html elements.
Synopsis
require_once 'HTML/QuickForm/Renderer/ObjectFlexy.php';
void HTML_QuickForm_Renderer_ObjectFlexy::setLabelTemplate (
string $template
)
Description
Set the filename of the template to render form labels. In your template, {label} is replaced by the unmodified label, {error} will be set to the error, if any. {required} will be true if this is a required field Eg.
{if:required}
<font color="orange" size="1">*</font>
{end:}
{label:h}
Parameter
-
string
$template -
Filename of template
Throws
throws no exceptions thrown
Note
This function can not be called statically.
HTML_QuickForm_Renderer_QuickHtml
HTML_QuickForm_Renderer_QuickHtml – Render form elements into HTML in an easy and flexible manner
Description
This renderer has three main distinctives: an easy way to create custom-looking forms, the ability to separate the creation of form elements from their display, and being able to use QuickForm in widget-based template systems.
All of the renderers allow you to create a custom-looking form. However, unlike the default renderer, QuickHtml is solely for creating custom forms and has the additional benefits discussed below.
It is often desirable to separate the creation of form elements and their accompanying rules from their actual display on a page. For example, in the MVC design pattern it may be useful to create the form elements and their rules in the Model classes which control how the submitted data will be saved (field lengths, allowed characters, etc.), but leave the rendering of those form elements to the View classes which only care about how to make the page look a certain way.
A widget is a chunk of re-usable html which can be used with other widgets to create a webpage. Any template system which supports widgets (and nearly all do) can be used with QuickHtml. An example widget may consist of a table with reserved places for the form elements. The form elements would be rendered into those places and then the form tags, any remaining form elements (such as hidden elements), and any accompanying javascript for validation would be wrapped around the table widget.
Usage example
The following is an example usage of the QuickHtml renderer. The
"template" system we use is just a simple html widget in which the form
elements are placed, but it could be replaced with a more complex
template system. A more complex usage example is in
docs/renderers/QuickHtml_example.php
QuickHtml renderer usage
<?php
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/QuickHtml.php';
// Create form elements and renderer
$form =& new HTML_QuickForm('tmp_form','POST');
$renderer =& new HTML_QuickForm_Renderer_QuickHtml();
// Create a hidden element. Note how we don't render it explicitly,
// rather we let QuickHtml render it for us at the beginning of the form.
$form->addElement('hidden','tmp_hidden');
// Create 2 radio elements. Note how we have to give a value when rendering
// them since that is the only way to tell them apart.
$form->addElement('radio','tmp_radio',null,null,'Y');
$form->addElement('radio','tmp_radio',null,null,'N');
// Create a group with a rule
$text = array();
$text[] =& HTML_QuickForm::createElement('text','',null,array('size' => 3));
$text[] =& HTML_QuickForm::createElement('text','',null,array('size' => 4));
$text[] =& HTML_QuickForm::createElement('text','',null,array('size' => 3));
$form->addGroup($text, 'tmp_phone', null, '-');
$form->addRule('tmp_phone','Phone number cannot be empty.','required',null,'client');
// Do the magic of creating the form. NOTE: order is important here: this must
// be called after creating the form elements, but before rendering them.
$form->accept($renderer);
// Create a very basic template for our form
$html_template = '
<div style="text-align: center; font-weight: bold;">QuickHtml - Basic Example</div>
<div style="text-align: center; background-color: #ccc; margin: 1px;">Phone: %phoneNumber%</div>
<div style="text-align: left; background-color: #ccc; margin: 1px;">Yes: %radioElementYes% No: %radioElementNo%</div>';
// Interpolate the form elements into our template
$html_template = str_replace('%phoneNumber%', $renderer->elementToHtml('tmp_phone'), $html_template);
$html_template = str_replace('%radioElementYes%', $renderer->elementToHtml('tmp_radio', 'Y'), $html_template);
$html_template = str_replace('%radioElementNo%', $renderer->elementToHtml('tmp_radio', 'N'), $html_template);
// The form tags, javascript, and hidden element will be wrapped around
// our html template
echo $renderer->toHtml($html_template);
?>
constructor HTML_QuickForm_Renderer_QuickHtml::HTML_QuickForm_Renderer_QuickHtml()
constructor HTML_QuickForm_Renderer_QuickHtml::HTML_QuickForm_Renderer_QuickHtml() – Constructor
Synopsis
require_once 'HTML/QuickForm/Renderer/QuickHtml.php';
void HTML_QuickForm_Renderer_QuickHtml::HTML_QuickForm_Renderer_QuickHtml (
void
)
Description
The constructor for HTML_QuickForm_Renderer_QuickHtml().
Throws
throws no exceptions thrown
HTML_QuickForm_Renderer_QuickHtml::toHtml()
HTML_QuickForm_Renderer_QuickHtml::toHtml() – Returns the HTML
Synopsis
require_once 'HTML/QuickForm/Renderer/QuickHtml.php';
string HTML_QuickForm_Renderer_QuickHtml::toHtml (
string $data
)
Description
Returns the HTML generated for the form.
Parameter
-
$data Any html to put inside the form tags. This would normally be the html template into which you have rendered the form elements.
Throws
throws no exceptions thrown
HTML_QuickForm_Renderer_QuickHtml::elementToHtml()
HTML_QuickForm_Renderer_QuickHtml::elementToHtml() – Renders a specific form element into HTML
Synopsis
require_once 'HTML/QuickForm/Renderer/QuickHtml.php';
string HTML_QuickForm_Renderer_QuickHtml::elementToHtml (
string $elementName
, string $elementValue
)
Description
Returns the HTML generated for a specific form element and marks that element as rendered.
Parameter
-
$elementName -
The name of the form element that is being rendered.
-
$elementValue -
The value given to the form element. This is only useful for elements that have the same name (such as a radio button), and can only be told apart based on the value assigned to them.
Throws
throws no exceptions thrown
Renderer infrastructure
If you want to modify an existing renderer or write a new one, this section will be of interest to you.
HTML_QuickForm_Renderer
HTML_QuickForm_Renderer – Abstract base class for renderers (package developer related)
Description
Defines the abstract methods that should be implemented by child classes.
QuickForm renderers implement the Visitor design pattern. That means that each form element has an accept() method that is called with a renderer instance as a parameter. This method does the following:
- If the element contains other elements (HTML_QuickForm_group and HTML_QuickForm itself) then it iterates over them calling each element's accept() method and calls the methods for rendering the container itself (e.g. startForm() and finishForm()).
- If the element is simple, then it calls the renderer's method for rendering itself (e.g. renderHeader()).
It may seem that renderer object has to have a renderConcreteElement() method for each HTML_QuickForm_concreteElement it may visit, but fortunately most of the elements have fairly similar rendering needs, so instead of separate renderTextarea() and renderCheckbox() we have a generic renderElement() method.
The renderer should take care of "accumulating" the information passed to its methods and of generating some type of output based on it. How this is implemented internally depends on the renderer type.
Creating your own renderer
The first thing you have to decide upon is how your renderer will accumulate the information. You'll probably have to create some data structures to keep it (unless you are going to pass the information to e.g. a template object at once).
Then you have to make concrete implementations for all the abstract methods defined in HTML_QuickForm_Renderer. One notable exception is renderHtml() method that is implemented only in the Default renderer and will probably stay this way.
You'll probably also want to add some public methods for customizing the output and getting the results of the renderer's work. But this depends on the type of the renderer very much.
If you want to contribute the renderer you made to QuickForm, consider the following
- Your code should be useful to other people (e.g. renderer for some obscure private template engine is a bad contribution).
- Your renderer should have non-trivial usage examples.
- And last but not least, you code will have to conform to PEAR coding standards.
If you have examples for additional uses of an existing renderer, that will be a welcome contribution, too.
HTML_QuickForm_Renderer::startForm()
HTML_QuickForm_Renderer::startForm() – Start visiting a form (package developer related)
Synopsis
require_once 'HTML/QuickForm/Renderer.php';
void HTML_QuickForm_Renderer::startForm (
object &$form
)
Description
Called when visiting a form, before processing any form elements
Parameter
-
object
&$form -
HTML_QuickForm object being visited
Throws
throws no exceptions thrown
Note
abstract
This function can not be called statically.
HTML_QuickForm_Renderer::finishForm()
HTML_QuickForm_Renderer::finishForm() – Finish visiting a form (package developer related)
Synopsis
require_once 'HTML/QuickForm/Renderer.php';
void HTML_QuickForm_Renderer::finishForm (
object &$form
)
Description
Called when visiting a form, after processing all form elements
Parameter
-
object
&$form -
HTML_QuickForm object being visited
Throws
throws no exceptions thrown
Note
abstract
This function can not be called statically.
HTML_QuickForm_Renderer::startGroup()
HTML_QuickForm_Renderer::startGroup() – Start visiting a group (package developer related)
Synopsis
require_once 'HTML/QuickForm/Renderer.php';
void HTML_QuickForm_Renderer::startGroup (
object &$group
, bool $required
, string $error
)
Description
Called when visiting a group, before processing any group elements
Parameter
-
object
&$group -
HTML_QuickForm_group object being visited
-
boolean
$required -
Whether a group is required
-
string
$error -
An error message associated with a group
Throws
throws no exceptions thrown
Note
abstract
This function can not be called statically.
HTML_QuickForm_Renderer::finishGroup()
HTML_QuickForm_Renderer::finishGroup() – Finish visiting a group (package developer related)
Synopsis
require_once 'HTML/QuickForm/Renderer.php';
void HTML_QuickForm_Renderer::finishGroup (
object &$group
)
Description
Called when visiting a group, after processing all group elements
Parameter
-
object
&$group -
HTML_QuickForm_group object being visited
Throws
throws no exceptions thrown
Note
abstract
This function can not be called statically.
HTML_QuickForm_Renderer::renderElement()
HTML_QuickForm_Renderer::renderElement() – Visit an element (package developer related)
Synopsis
require_once 'HTML/QuickForm/Renderer.php';
void HTML_QuickForm_Renderer::renderElement (
object &$element
, bool $required
, string $error
)
Description
Called when visiting an element
Parameter
-
object
&$element -
HTML_QuickForm_element object being visited
-
boolean
$required -
Whether an element is required
-
string
$error -
An error message associated with an element
Throws
throws no exceptions thrown
Note
abstract
This function can not be called statically.
HTML_QuickForm_Renderer::renderHeader()
HTML_QuickForm_Renderer::renderHeader() – Visit a header (package developer related)
Synopsis
require_once 'HTML/QuickForm/Renderer.php';
void HTML_QuickForm_Renderer::renderHeader (
object &$header
)
Description
Called when visiting a header element
Parameter
-
object
&$header -
HTML_QuickForm_header element being visited
Throws
throws no exceptions thrown
Note
abstract
This function can not be called statically.
HTML_QuickForm_Renderer::renderHtml()
HTML_QuickForm_Renderer::renderHtml() – Visit a raw HTML/text element (package developer related)
Synopsis
require_once 'HTML/QuickForm/Renderer.php';
void HTML_QuickForm_Renderer::renderHtml (
object &$data
)
Description
Called when visiting a raw HTML/text pseudo-element
Implementation of the method
HTML_QuickForm_html elements are used to directly add HTML to the form output. Thus they are useful with the Default renderer, but not with template-based one. Default renderer is currently the only one actually implementing this method, all others silently ignore HTML_QuickForm_html elements.
Parameter
-
object
&$data -
HTML_QuickForm_html element being visited
Throws
throws no exceptions thrown
Note
abstract
This function can not be called statically.