Click to See Complete Forum and Search --> : 0 values entered in form not recognised by CGI


idonalds
08-08-2006, 11:15 AM
This is a little odd, but persistent. I have set up a HTML form and CGI to receive numerical values from the form. However, if I enter '0' the CGI thinks a value has not been entered. To enter zero I need to put '00'

Has anyone encountered this?

Thanks!

chrisranjana
08-08-2006, 07:43 PM
How you are validating that form field in perl ?

robertketter
08-08-2006, 09:37 PM
0 (ZERO) is false in perl. So if you are checking $field and its value is 0, it is false and therefore has no value.

idonalds
08-09-2006, 04:06 AM
Thanks for the replies!

The CGI takes in the HTML variable as shown here:
$hold_distance_up = $query->param('distance_up');
$hold_distance_up is expected to be a number between 0 and 100000. However, 0 is seen as a NULL value, so Perl objects to this. But, I have seen other people sites accept 0 as a value and work perfectly well.

Thanks again.

robertketter
08-09-2006, 06:50 AM
here try this...


$hold_distance_up = $query->param('distance_up');
if (!$hold_distance_up){ $hold_distance_up == 0;}
:)

Charles
08-09-2006, 07:24 AM
here try this...


$hold_distance_up = $query->param('distance_up');
if (!$hold_distance_up){ $hold_distance_up == 0;}
:)Please, this is PERL and so that can be shortened to:$hold_distance_up = $query->param('distance_up') || 0;

idonalds
08-09-2006, 08:10 AM
Thanks again,

I can now use 0 in my web form. The problem I think is that I was using these variables in an AND comparison in my Perl CGI.

0 is actually sent to the CGI though.

Still confused, but it works.