(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Kerio Reseller
Printer Friendly Version

Using Multiple Submits with Perl CGI


2008/01/02

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.







Enter your email address for automatic notification of new posts here
(be sure to whitelist 'feedburner.com' if you use spam filtering)

Or use any RSS reader

Delivered by FeedBurner





Views for this page
Today This Week This Month This Year  Overall
55911,136 1,136

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

pavatar.jpg
Psst - Wanna work for yourself?

More:
       - Perl
       - Programming
       - Code
       - Blogging




Unix/Linux Consultants


http://thatitguy.com Business networking servers, Linux and Unix experts. In business since 1997! Windows and Exchange to Samba and Scalix migration experts.


http://echo3.net/ Unix/Linux Custom Applications, Web Hosting, C/C++ Programming Courses


http://www.cleverminds.net Need expert advice? Want a second opinion? CleverMinds is a one-stop-shop for a wide range of technology solutions. We support Unix, Linux, SCO as well as CMS, ecom, blogs, podcasts, search engines consulting and more. Contact us at web2.0@cleverminds.net 0r (617) 894-1282



Twitter
  • Nov 23 13:01
    I need coffee before I will even open the door, never mind go out there. That's completely non-negotiable, by the way.
  • Nov 23 12:56
    It's COLD and my wife wants us to go work in the yard. Do you think I can have her arrested for cruelty? Probably not as she's going too.







Coming Attractions

My Favorites

Change Congress


Related Posts