CGI and Perl

Image Buttons

Image buttons are the same as Submit buttons, except that an image is displayed instead of text. For example, you can place an image of a mailbox that could cause the action of mailing the form contents to a certain user. Using raw HTML, image buttons are created with the INPUT tag with TYPE image, as seen here:

<INPUT TYPE=image SRC="images/doit.gif" NAME='action'
        VALUE='Doit' ALIGN=middle>

Using CGI::Form, this is a call to the method image_button, as shown in the following example:

$q->image_button( -src=>"images/doit.gif", -name=>'action', -value=>'Doit',
                   -align=>'middle' );

-src is used to specify the URL to the image which is to be displayed; -name specifies an arbitrary name associated with the image button; -value specifies an arbitrary value. The -name and -value parameters are important to distinguish the action between multiple image buttons on a form. -align is used to line up the image with the text that follows it. The possible values for -align are top, middle, and bottom.


Listboxes are fields that contain a scrollable list of text strings for single or multiple selection. You can use listboxes for such things as specifying a state (single selection) or product of interest (multiple selection). Use the SELECT and OPTION tags, as shown in the following lines, to create a listbox:


Using CGI::Form, this calls the scrolling_list method:

@states=( `CA', `WA', `OR', `NV', `AZ' );
 $q->scrolling_list( -name=>'State', -values=>\@states, -default=>'CA',
                     -size=>3 );

The nice feature of using scrolling_list in CGI::Form is that the options can be stored within Perl arrays, which makes working with the data easier.

by BrainBellupdated