Tired of authoring dull and dreary Web forms everyday? Fed up of programming JavaScript validations day-in and day-out? Then, the HTML_QuickForm package is just the solution for which you are looking. In the first part of this two-part tutorial, I'll get you started with the basics of building Web forms using this resourceful PEAR package.
Using HTML_QuickForm To Manage Web Forms, Part 1 - My First HTML_QuickForm (Page 3 of 13 )
As you might have guessed, the aim of this article is to demonstrate the ease with which one can generate a Web form using the HTML_QuickForm package. Click on the link below to view the code listing for my first Web form:
Load this example in the browser to view the following output:
A quick review of the code and you will see that I have not hard-coded any <FORM> elements - yet, the browser displays a neat little Web form when the script is loaded. At this point, I can safely conclude that this package definitely fulfills one of my original goals: I should not be required to type any HTML code during development.
Now it's time to dissect the code listing. For starters, I have to "require" PHP file that contains the definition of the HTML_QuickForm() class as shown below:
<?php
// include the required PEAR class require_once 'HTML/QuickForm.php';
// define a new HTML_QuickForm object $obj_registration_form = new HTML_QuickForm('frmRegistration');
// snip
?>
Moving to the next statement - I have created a new instance (called "$obj_registration_form") of the HTML_QuickForm() class. The constructor of this class has one compulsory parameter - the name of the Web form. The rest of the input parameters are optional; among other things, these optional parameters allow me to specify values for the different attributes associated with the <FORM> HTML element.
Note that the default value of the "method" attribute is "POST" the above Web form. So, if I wish to use the "GET" method, I need to pass this value explicitly to the constructor.