APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Programming > Using Multiple Submits with Perl CGI
Printer Friendly Version




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:

#!/usr/bin/perl
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.


If this page was useful to you, please click to help others find it:  
Your +1's can help friends, contacts, and others on the web find the best stuff when they search.


2 comments




More Articles by Anthony Lawrence - Find me on Google+



Click here to add your comments





Sat Nov 20 09:49:19 2010:   JaniceLEvangelista
http://www.areyoupregnant.net
gravatar
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:   TonyLawrence

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

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-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. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

My Hard Truths about Easy Money on the Internet will show you how to make money on the Internet!

book graphic Internet Income guide



Buy Kerio from a dealer who knows tech: I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals
pavatar.jpg

This post tagged:

       - Blogging
       - Code
       - Perl
       - Programming




Unix/Linux Consultants

Skills Tests

Guest Post Here