cvsuser 02/03/06 14:59:21
Modified: P5EEx/Blue/P5EEx/Blue/Widget/HTML Checkbox.pm
Log:
fixed bug where checkbox is not checked and no data is posted
Revision Changes Path
1.2 +15 -3 p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML/Checkbox.pm
Index: Checkbox.pm
===================================================================
RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Widget/HTML/Checkbox.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -w -r1.1 -r1.2
--- Checkbox.pm 5 Feb 2002 22:16:05 -0000 1.1
+++ Checkbox.pm 6 Mar 2002 22:59:21 -0000 1.2
@@ -1,10 +1,10 @@
######################################################################
-## $Id: Checkbox.pm,v 1.1 2002/02/05 22:16:05 spadkins Exp $
+## $Id: Checkbox.pm,v 1.2 2002/03/06 22:59:21 spadkins Exp $
######################################################################
package P5EEx::Blue::Widget::HTML::Checkbox;
-$VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
+$VERSION = do { my @r=(q$Revision: 1.2 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
use P5EEx::Blue::P5EE;
use P5EEx::Blue::Widget::HTML;
@@ -68,11 +68,23 @@
my ($name, $value, $html);
$name = $self->{name};
$value = $self->get_value();
+
+ # HTML checkboxes are funny.
+ # They don't submit anything unless checked.
+ # So we have to send a hidden variable to unset them.
+ # Then they are reset if they are still really checked.
+ # This relies on the behavior that browsers will post values
+ # in the order in which they occurred in the HTML.
+ # (This is not specified explicitly in standards docs but
+ # universally implemented. If anyone knows differently, please
+ # let me know.)
+
+ $html = "<input type=\"hidden\" name=\"$name\" value=\"0\" />";
if ($value) {
- $html = "<input type=\"checkbox\" name=\"$name\" checked />";
+ $html .= "<input type=\"checkbox\" name=\"$name\" value=\"1\" checked />";
}
else {
- $html = "<input type=\"checkbox\" name=\"$name\" />";
+ $html .= "<input type=\"checkbox\" name=\"$name\" value=\"1\" />";
}
$html;
}