APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Using Multiple Submits with Perl CGI

I frequently use the Perl CGI.pm module for forms. While re-writing a local (in my office) app yesterday, I was reminded that you don't often see people using multiple submits on forms. There's no reason why you cannot, and it can add functionality. Consider the following (just an image, it's not functional):

picture of form with multiple submits

This form lets me enter and track time and mileage for my clients. I use pre-paid time for many customers, so I need this to know when to renew the time, to send statements of time used, and to bill for mileage (which I do separately at the and of each month).

Notice that there are five "Submit" boxes at the bottom of the screen. They all have different values:

<br /><input type=submit name=posting value ='Post' >
- - <input type=submit name=statement value ='Statement' >
- - <input type=submit name=Home value ='Home' >
- - <input type=submit name=raw value ='Raw' >
- - <input type=submit name=kill_last value ='Kill Last'>

At the top of my code, I test for those values:

use CGI qw(:all :delete_all);
delete_all() if param('Home');
posting() if param('posting');
getting() if param('posting');
getting() if param('getting');
kill_last() if param('kill_last');
raw() if param('raw');
statement() if param('statement');

Those subroutines do the obvious tasks, and either exit or return back for more processing. Note the special handling of the "Home" button: if I didn't do that, all set variables would come right back to us; that's how CGI.pm works, and it's very convenient most of the time, but when we hit "Home", we want a fresh start - nothing set.

Also note that I had to explicitly include that "delete_all" feature. I often forget to do that in my initial efforts and the code just blows up without it.

You can do just about whatever you want with multiple submits. With the CGI.pm module, you do have to clear variables when you do not want to pass them on to subroutines, but that's easy to do.. you can also delete specific variables if you need fine control, see the CGI documentation.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Using Multiple Submits with Perl CGI


Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Anthony Lawrence

Sat Nov 20 09:49:19 2010: 9124   JaniceLEvangelista


Do you have any sample working by which we can implement multi page form submit using perl's Mechanize module?

Sat Nov 20 11:24:32 2010: 9125   TonyLawrence


No. I had never even heard of that until you mentioned it.

Kerio Samepage

Have you tried Searching this site?

Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. (Tim Berners-Lee)

This post tagged: