Edited By
Martin JansenUsage examples
Creating the form in "table mode"
Creating a form in "table mode" means that the package returns the complete form in a fixed width table. Whilst this does not work very well for most frontend websites, it is a very convenient way to create forms during development phase or for backend systems where the design does not matter (much).
Creating a form
<?php
require_once "HTML/Form.php";
$form = new HTML_Form('receivingscript.php');
$form->addText("name", "What's your name?");
$form->addText("email", "What's your email address?");
$form->addPassword("password", "Please enter the desired password");
$form->addPlaintext("Tip", "Your password should be hard to guess");
$form->addSubmit("submit", "Submit");
$form->display();
?>
This will display a table where the left column holds the labels of the different fields. In the right column the different fields are placed.
Displaying single form tags
Apart from retrieving the table as a whole, one can also use the API of HTML_Form to directly display single form tags.
Directly displaying form tags
<?php
require_once "HTML/Form.php";
$form = new HTML_Form('receivingscript.php');
$form->displayText("name", "What's your name?");
?>
The above example will print the HTML markup
being necessary to render a text input field. It will not print
the surrounding <form />
tag or something
else!
Returing single form tags
Similar to displaying form tags with the display*() functions HTML_Form can also return the tag instead of printing it.
Returning form tags
<?php
require_once "HTML/Form.php";
$form = new HTML_Form('receivingscript.php');
$str = $form->returnPassword("password", "Choose a password");
?>
The variable $str
now contains
HTML markup like
<input type="password" name="password" />
.