Developing HTML Forms in PHP using QuickForm
Display Form
We can display the form on the browser by calling the display() function. This function does not receive any arguments. We use the function in conjunction with the validate() and process() functions.
if(!$form->validate())
{
$form->display();
}
else
{
$form->process(‘on_validate’);
}
The logic that we construct is that if the form does not validate (based on our validation and filtering rules) then the form should be displayed to the browser otherwise the function that handles the submitted data should be called (on_validate($data) on the example).
Default Values
Quickform allows us to specify default values for our form elements. These are values that will populate the fields when the form is being rendered on the browser and can be altered by the user if the element is not frozen (when an element is frozen then its default value is display but the user cannot alter its value).
We can specify default values for a form element by calling the setDefault() function. The function receives an associative array as an argument where the key is the name of the field and its value maps to the value of the element.
The default values approach is an excellent method in populating the fields with values that the user has entered in a previous session.
Process Submitted Values
We have specified what types of elements we want to use, we have specified restrictions that should be applied on the elements, we have set default values on the fields and we have displayed the form on a web page.
The final issue that we need to address is how we process the user submitted values. In ‘Display Form’ section, we specified a callback function that should be called upon successful form submission.
$form->process(‘on_validate’);
We need to define a function that will have one argument which QuickForm will use to pass on the submitted user values.
function on_validate($data)
{
// Do something with $data
}















Very concise. Thanks, I’ll be using this info!
[...] Developing HTML Forms in PHP using QuickForm (dountsis.com, en) [...]