Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, I am having a slight problem in using the param function in cgi. I have a web page with the following
lots of rubbish here <FORM ACTION="test.cgi" METHOD="POST" ENCTYPE="multipart/form-data"> <input type="checkbox" name="option_and" value="AND">ANDfilter<br> <input type="checkbox" name="option_or" value="OR">ORfilter<br> <INPUT TYPE="submit" NAME="Submit" VALUE="Submit"> </FORM>
in test.cgi i want to confirm which checkbox was checked
print "Content-type: text/html\n\n"; print "<html><head><title>TEST</title></head>"; $queryand = new CGI; @array_and = $queryand->param('option_and'); @array_or = $queryand->param('option_or'); if (@array_and = 'AND') {print "<P>FilterAND = @array_filter";} if (@array_or = 'OR') {print "<P>FilterOR = @array_filter_or";} print "</html>";
However, when i check the OR box test.cgi prints FilterAND not FilterOR. Any suggestions? Thanks

Replies are listed 'Best First'.
Re: form cgi
by cbro (Pilgrim) on Jun 29, 2005 at 16:38 UTC
    You're assigning not checking.
    That is, you meant "==", not "=".
    You want to use the "eq" operator for strings anyway, so change.
    You also want to use a scalar, not an array.
    Corrections:
    $quearyand = new CGI; $array_and = $queryand->param('option_and'); $array_or = $queryand->param('option_or'); if ($array_and eq "AND") { print .... } if ($array_or eq "OR") { print ... }
      thanks for that
Re: form cgi
by sk (Curate) on Jun 29, 2005 at 16:28 UTC
    I am confused about this statement

    @array_and = 'AND'
    You are making an assignment in the if statement and besides it is an array and not a scalar

    . Let me see if I can get a proto version for you

    Update:

    use CGI qw(:standard Vars); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; print header; print start_html("Test"); my %form = Vars(); map { print ("$_ = $form{$_}<br>\n"); } keys(%form); print end_html();
    I am using Vars() to get all the form elements and then looping through it to print it on the screen. What you want from the above code is the  %form hash and you can check for conditions there. I had to modify the variables you were using because i am not sure quite sure where you get @array_and_filter etc. Anyways hopefully this points you in the right direction.

    cheers

    SK