For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > September 2005 > CGI.PM and IF statment....









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author CGI.PM and IF statment....
David Gilden

2005-09-10, 3:55 am

The if statement below does not seem to work as expected//

Given in the HTML:
<select name=3D"message type">
<option value=3D"0">Choose type message</option>
<option value=3D"Comment">Comment about a recent performance or recording</=
option>
<option value=3D"Booking inquiry">Concert or Event Booking inquiry</option>
<option value=3D"Personal message">Personal message</option>
</select>


and in the perl:

#!/usr/local/bin/perl=20
use CGI qw/:standard/;
use strict;

#and other stuff...

my $mt =3D param('message type');

if (length($mt) =3D=3D 0) {
print redirect("/pages/error.html");
exit;
}

This should only redirect it someone has not made a 'selection' ....
what am I missing?

Thanks!

Dave
(kora musician / audiophile / webmaster @ www.coraconnection.com / Ft. Wor=
th, TX, USA)
Charles K. Clarkson

2005-09-10, 3:55 am

David Gilden <mailto:dowda@coraconnection.com> wrote:
: The if statement below does not seem to work as expected//
:
: Given in the HTML:
: <select name="message type">

Don't use white space in form field names.

<select name="message_type">


: and in the perl:
:
: #!/usr/local/bin/perl
: use CGI qw/:standard/;
: use strict;
:
: #and other stuff...
:
: my $mt = param('message type');

my $mt = param('message_type');


I also don't use white space in option values.


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328

Ovid

2005-09-10, 6:55 pm

--- David Gilden <dowda@coraconnection.com> wrote:

> my $mt = param('message type');
>
> if (length($mt) == 0) {
> print redirect("/pages/error.html");
> exit;
> }
>
> This should only redirect it someone has not made a 'selection' ....
> what am I missing?


Unless you send bad HTML or someone's messing with their submit data,
it's very unlikely that someone won't have made a selection. In that
case, you want to check the "truth" of the selection value, not the
length. As previously noted, the length of "0" is 1, but you really
don't care about that. I would leave the value as 0 or set it to the
empty string and write the condition like this:

if ($mt) { ... }

Cheers,
Ovid

--
If this message is a response to a question on a mailing list, please send
follow up questions to the list.

Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com