Using HTML_QuickForm To Manage Web Forms, Part 1 - Adding Standard HMTL FORM Elements (Page 5 of 13 )
Note that the number of input parameters passed to the addElement() method varies with the nature of the element added to the Web form. While it is sufficient to pass only two values for the "html" and "header" elements, it is a different ball game when it comes to adding standard HTML <FORM> elements. Take a look at the following code snippet:
First, I have added a "text" input control. This time, you'll notice that I have passed four parameters - first, the keyword "text" indicates that I want to render a "text" <INPUT> element, the second parameter represents the "name" of the text field, the third is the the "label" to displayed along side the control and finally, an array consisting of key-value pairs. Take a close look at this array and you will notice I have assigned values for some commonly used attributes of the <INPUT> HTML element.
Things are similar for a <TEXTAREA> control. The only major change is the use of the keyword "textarea" for obvious reasons. You will also note that the array, i.e. the fourth optional parameter of the addElement() method, has been updated to define the size of the text area.
Next, I want to add a <SELECT> control. As you might have guessed, I pass the "select" keyword along with the control name and text for display label. But what about the options to be displayed in the drop down? No sweat - all I need to do is define an array with set of key-value pairs, where the value is the text displayed in the browser and the key represents the value submitted to the server for the selected <OPTION>.
This is followed by the "radio" <INPUT> control. Once again, it's the "radio" keyword that does the trick. Of course, I've added another "radio" button with the same "name" because I want the user to select only one value - this is akin to the definition of two <INPUT> radio buttons with the same "name" in good ol HTML.