1. Home
  2. Computing & Technology
  3. Perl

Working with CGI.pm In-Depth
Creating Submit and Reset Buttons

by Kirk Brown
for About.com

Every web form needs a way to submit it, and the standard simple method is to drop in a submit button. There are other ways, like using ajax or using an image instead of a button, but the submit button is a standard interface element that people have come to expect. Creating a submit button is as simple as calling CGI.pm's submit function:
print $cgi->submit();
Which will output:
<input type="submit" name=".submit" />
There are some optional attributes you can pass in, all of which are detailed in the general form attributes section. Let's look at the most common one - what's printed on the button itself. This is handled through the -value attribute. So say, for example, you want your button to say 'Save Changes':
print $cgi->submit(
-value => 'Save Changes'
);
That will print:
<input type="submit" name=".submit" value="Save Changes" />
You can also pass in the optional -name attribute if you want to give it something other than the default name value of .submit:
print $cgi->submit(
-value => 'Save Changes',
-name => 'submit_button'
);
Which will output:
<input type="submit" name="submit_button" value="Save Changes" />
Finally, the less used, but still fun reset button works in the same manner. Just call it with the reset function like so:
print $cgi->reset();
And you end up with:
<input type="reset" name=".reset" />
Explore Perl
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Perl
  4. CGI & Web
  5. Working with CGI.pm In-Depth - How to build submit and reset buttons with CGI.pm>

©2009 About.com, a part of The New York Times Company.

All rights reserved.