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

I am using CGI.pm to create checkboxes for the attachment stripper. When some checkboxes clicked and submitted, the script only sometimes functions as expected. However, there are times submission fails. i.e. "checked" boxes are not recognized. Any insights, comments, or suggestions are appreciated.
use CGI; ..... my $query = new CGI; .... print $query->startform(-method => 'GET'); ... #obtaining the emails that were intended for the user. #printing the To, Subject,etc. #Calling sub print_checkbox for the emails that were stripped for the +user. ... print "<P>",$query->reset; print "<P>",$query->submit; print $query->endform; # match_form called. sub print_checkbox { #print" I am here $_[0]<br>"; print "<P>Do you want this e-mail message? ", $query->checkbox_gro +up(-name =>'e_check',-values=>[$_[0]],-label=>[$_[0]]); } sub match_form { my $matcher="meep.tc.onramp.ca"; #for testing purposes my @turned_on = ($query->param('e_check')); print join(" ", @turned_on), "###\n"; my $email_checked; print " I am in end_form before for each loop<br>"; foreach $email_checked (@turned_on){ if ($email_checked =~ /$matcher/) { #this part of the code should be executed #for all the emails checked.. yet, executed only sometimes #qmail-inject the mail } else { print "Nothing Equals, $email_checked<br>"; } } }

Replies are listed 'Best First'.
Re: CGI.pm Submit inconsistency
by tadman (Prior) on Sep 26, 2002 at 18:20 UTC
    You've got some renegade indentation going on there. Anyways, a few things to watch out for.

    When putting a scalar into a regular expression, be sure to encapsulate it properly. Remember that '.' is a special character in regexp context.
    if ($email_checked =~ /\Q$matcher\E/)
    Also, you can declare your looping variable within the loop itself, like this:
    foreach my $email_checked (@turned_on)
    Provided your @turned_on array is populated correctly, which I'm only presuming since the output of your debugging code is not shown, then this should work. Are you sure you're actually getting a series of "Nothing Equals..." messages?
      @turned_on remains empty even when I have checked boxes. However, it is not always empty. Sometimes, @turned_on has the right checked boxes. For example, the script may function as required when I visit the webpage now. Then it does not if I refresh or so.(randomly though). Can't seem to obtain any pattern. The inconsistency is bothering me. Would it have to do anything with the browser(although I seriously doubt that). Could it be because I am invoke the script while another process is using it? Thanks
Re: CGI.pm Submit inconsistency
by fglock (Vicar) on Sep 26, 2002 at 18:23 UTC
    some hints: - try with other browsers; - replace print " I am here $_[0]<br>"; with: print " I am here <pre>#$_[0]#</pre><br>";