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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
adding an extra @required value, if checkbox is checked

 



pogohound
New User

May 4, 2003, 5:32 PM

Post #1 of 4 (745 views)
adding an extra @required value, if checkbox is checked Can't Post

Hi,

I wonder if anyone could advise me on what I need to do to enable the following.

I currently have the following @required fields setup:

@required = ('forename','surname','email');

Now, here's the problem. I have a checkbox which asks the user if they'd like a call-back. Obviously if they check the box, then I'm going to need their telephone number. Which means I'd like to make this a required field, but only when the call-back checkbox has been checked.

i.e call-back checkbox unchecked =
@required = ('forename','surname','email');

call-back checkbox checked =
@required = ('forename','surname','email','telephone');

How would I go about this?

I'd be very, very grateful for any help.

Many thanks,
Johnny


davorg
Thaumaturge / Moderator

May 5, 2003, 8:58 AM

Post #2 of 4 (743 views)
Re: [pogohound] adding an extra @required value, if checkbox is checked [In reply to] Can't Post

Perhaps something like this:


Code
my @required = qw(forename surname email); 
push @required, 'telephone') if param('callback')'

This, of course, assumes that your call-back checkbox is called "callback".

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


pogohound
New User

May 6, 2003, 11:35 AM

Post #3 of 4 (739 views)
Re: [davorg] adding an extra @required value, if checkbox is checked [In reply to] Can't Post

Hi Dave, thanks for the reply.

Yes, the checkbox is called "callback". When I try inserting the code the script will no longer run, I get a '500' error. What am I doing wrong?

Thanks,
Johnny


davorg
Thaumaturge / Moderator

May 6, 2003, 12:40 PM

Post #4 of 4 (737 views)
Re: [pogohound] adding an extra @required value, if checkbox is checked [In reply to] Can't Post


Quote
What am I doing wrong?


You're using my code without giving it the most cursory check for sanity :)

Not sure what drugs I was on that day, but the second line of my code should read:


Code
push @required, 'telephone' if param('callback');


Of course, I was also assuming that you were using CGI.pm. If not then you'll need to substitute whatever parameter extraction magic that you were previously using.

A general tip - when you get the generic "500 error" you'll usually find something far more useful in the web server error log.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


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

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