CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Form processing



Sep 13, 2000, 5:56 AM

Post #1 of 5 (1166 views)
Form processing Can't Post

I have a form (on a webpage) that is processed by a perl script. The form takes users input for salary and time, and upon Submit, the script calculates how much a worker earned while on break. The form has 2 fields, hourly and salary, What I am wondering is how to tell the script to process whichever field the user fills in. In other words, if a worker is hourly then he would type his hourly wage into a field, and the script would need to ignore the salary field because it would be blank...and vice-versa. I am thinking the answer is along the lines of 'IF this field is filled in THEN do this, ELSE do something else' - but just not 100% sure how to code it. Any and all help is greatly appreciated!



Sep 13, 2000, 11:48 AM

Post #2 of 5 (1166 views)
Re: Form processing [In reply to] Can't Post

Your right,

if ($form{'hourly'} eq ""){
then do what ever with salary
}elsif ($form{'salary'} eq "")
then do what ever with hourly



Sep 13, 2000, 3:43 PM

Post #3 of 5 (1166 views)
Re: Form processing [In reply to] Can't Post

What if they're stupid and fill out both fields?

Perhaps you ought to consider using an input field for salary and a radio button or selection list for the pay type.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

<input type="text" name="pay">
<select name="type">
<option selected> hourly
<option> salary

Then you can ...

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ( param('type') eq 'salary' ) {
# do something with param('salary')
} elsif ( param('type') eq 'hourly' ) {
# do something else with param('salary')
} else {
print "Whatchu talking about, Willis?"

If you don't use, substitute param() for whatever is appropriate to your enviroment (ie, [taking perlkid's example] $form{'type'}).

This method also has the added benefit of (partially) sanitizing your input and only giving them one choice. :-)


Sep 13, 2000, 9:58 PM

Post #4 of 5 (1166 views)
Re: Form processing [In reply to] Can't Post

he he he,

Dummy Proof.



Sep 14, 2000, 5:28 AM

Post #5 of 5 (1166 views)
Re: Form processing [In reply to] Can't Post

Thanks All!

The "what if they fill out Both fields" point is good, because just before I read that post I was thinking "now that it works, I need some error checking for the form..."

So now I'll head down that path!

Thanks for everything!!


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives