in reply to Re: checkbox help
in thread checkbox help

that didn't work.... because i'm printing out more than just checkbox data. Here's the whole sub routine:
sub getdata { # $_ is the form element name and $in{$_} is the cont +ents. if ($action eq $SENDSTR) { open(OUT,">>$xls_file") || print "could not open $xls_file" ; } foreach ($query->param) { $in{$_} = $query->param($_); if ($_=~/^c_/) { $check{$_}="CHECKED" } #checkbox if ($_=~/^r_/) { $check{$_.$in{$_}}="CHECKED" } #radio if ($_=~/^s_/) { $check{$_.$in{$_}}="SELECTED" } #Select if ($action eq $SENDSTR) { $in{$_}=~s/\r\n/ /g; if ($_ !~/action|lang/) { # don't print these fields to X +LS file print OUT "$in{$_}\t"; } } $in{$_}=~s/\r\n/<br>/g || $in{$_}=~s/<br>/\n/g; $in{$_}=~s/"/&quot;/g; $in{$_}=~s/'/&rsquo;/g; $in{$_}=~s/\$/&\#36;/g; } # end foreach if ($action eq $SENDSTR) { print OUT "$today\t"; print OUT "\n"; close(OUT); } }

Replies are listed 'Best First'.
Re^3: checkbox help
by ikegami (Patriarch) on Mar 05, 2007 at 18:30 UTC

    I have no idea what I was thinking when I wrote the first part of that post. Like I said in the second half, unchecked checkboxes are not in the list of params. As per the HTML spec, they are not sent by the client to the server. You need to loop over the fields you want to output, not over the params

    my @fields = qw( ... c_... c_... c_... ... ); foreach (@fields) { $in{$_} = $query->param($_); if (/^c_/ && defined($in{$_})) { $check{$_} = "CHECKED"; } ... }