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

Using Multiple Submits with Perl CGI

© January 2008 Anthony Lawrence

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


Inexpensive and informative Apple related e-books:

iOS 8: A Take Control Crash Course

Take Control of Upgrading to El Capitan

Photos for Mac: A Take Control Crash Course

Take Control of Automating Your Mac

Take control of Apple TV, Second Edition

More Articles by © 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.


Printer Friendly Version

Have you tried Searching this site?

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

Printer Friendly Version

Science is what we understand well enough to explain to a computer. Art is everything else we do. (Donald Knuth)

Linux posts

Troubleshooting posts

This post tagged:





Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode