CGI Forms   «Prev  Next»

Lesson 7Widgets
ObjectiveLearn about specific widgets and what they do.

CGI.pm FORM defaults

The different FORM elements and the widgets the browser creates from them were listed in the first lesson of this module. In this lesson, we will look at each of them in sufficient detail for you to make use of their various features.
Optional features for the widgets are accessed via attributes in the HTML elements. For example, to set the size of a text field, you would use the SIZE attribute in the HTML like this:
<INPUT TYPE=TEXT SIZE=35>

This would give you a text field with enough space to type 35 characters. Keep in mind that most of these optional features do not work the same on different browsers.
I have put together a list of widgets and their attributes. You will need to study this list before you complete this lesson's exercise. So, without further ado:
Perl Device List

CGI.pm FORM defaults

CGI.pm has very reasonable defaults for these form elements. These are as follows:
attribute default
method method="POST"
action action="myscript.cgi" or whatever your current cgi script is called.
enctype enctype="application/x-www-form-urlencode"

We should not ever need to change the enctype within our form (in fact we should avoid even trying to do so). If you want to create a multi-part form (for uploading files etc) we create this in a different manner.
We must use this syntax for multi-part forms if we want CGI.pm to handle them properly. We create a multi-part form like this:

print start_multipart_form({-action=>"myscript.pl", -method=>"POST"});
# print form internals.
print end_form();

Perl Widget - Exercise

Click the Exercise link below to create a form using tons of widgets.
Perl Widget - Exercise