HTML_Form is a Pear class that allow you to build HTML Form
writing less HTML.
We'll explain trough different examples how to
use this class.
The basics
A form is consist of different type of input :
text, select, textarea, checkbox, radio button, hidden field
W3C Definition
Quick sample :
<form>
<input type="text" name="input_name" value="input_default_value">
<select name="select_name">
<option>value 1</option>
<option>value 2</option>
</select>
<textarea name="textarea_name">
default value
</textarea>
</form>
The problem
Too many times when writing php form
you do :
echo '<input type="text" name="variable_name" value="'.$default_value.'">";
foreach($options as $option) {
echo '<input type="text" name="option'.$option->name.'" value="'.$option->value.'">";
}
The solution
PEAR::HTML_Form, no other PEAR dependency, it
allow you to build simple form without writing any HTML code, just use
the 'add' method then display the form or call directly the methods.
A quick table form, with 2 columns :
require 'HTML/Form.php';
$form = new HTML_Form('HTML_Form.php','post');
$form->addText('text_name', 'text title :');
$form->addTextarea('textarea_name', 'textarea title : ');
$choices = array(1,2,3,4,5,6);
$form->addSelect('select_name', 'select title : ', $choices);
$form->addSubmit('submit');
$form->display();
Another way of using it, calling
directly the methods :
echo HTML_Form::returnSelect('select_name', $choices);
// OR
$output_variable = $message . HTML_Form::returnSubmit('submit') . $end_of_page;
Tips
If you want to add some _javascript_ here
is how to do it :
$form->addText('text_name" class="moz-txt-link-rfc2396E" href="">"_javascript_:js_action()', 'text title :');
// OR
$variable = HTML_Form::returnSubmit('submit" footer">
Last edited on Monday, September 5, 2005 12:37:15
pm.