CGI and Perl

Checkboxes

Checkboxes are used for Boolean values. They can be used for things that require a yes or no response. Using raw HTML, you create checkboxes by using the INPUT tag with TYPE checkbox as shown in the following line:

<INPUT TYPE=checkbox NAME='want-notification' VALUE='yes' CHECKED>

Using CGI::Form, this is a call to the method checkbox:

$q->checkbox( -name=>'want-notification', -value=>'yes', -checked=>'true' );

Hidden Fields

Hidden fields are fields that do not appear on the form. At first you may wonder, "Why have hidden fields?" It turns out that hidden fields are an essential tool for solving the problem of maintaining state between transactions. In Chapter 16, "Advanced CGI/HTML," the concept of maintaining state will be discussed in great detail. Using raw HTML, you can create hidden fields using the INPUT tag with TYPE hidden:

<INPUT TYPE=hidden NAME='runningTotal' VALUE='36.25'>

Using CGI::Form, the following is a call to the method hidden:

$q->hidden( -name=>'runningTotal', -value=>'36.25' );

It turns out that one of the primary programming issues regarding HTTP and CGI is that of state. It is often essential for a programmer to keep track of certain values as the user is navigating through the user interface. This will become more obvious as you go through some of the examples.

Submit Buttons

Submit buttons initiate the action of sending the form data back to the server. A single form may have more than one Submit button to indicate what action is being performed. To create Submit buttons, use the INPUT tag with TYPE submit:

<INPUT TYPE=submit NAME='action' VALUE='Submit'>

Using CGI::Form, the following calls the method submit:

$q->submit( -name=>'action', -value=>'Submit' );

Reset Buttons

Reset buttons also appear as push buttons. The effect they have on the form, however, is to reset the contents of the form to its initial state of either blank fields or default values. Create Reset buttons by using the INPUT tag with TYPE reset, as shown here:

<INPUT TYPE=reset VALUE='Clear'>

Using CGI::Form, call the method reset, in the following manner:

$q->reset( -value=>'Clear' );

by BrainBellupdated
Advertisement: