Valid values for $form $isChecked?

Permalink 1 user found helpful
I'm working on a custom block that has a search form in it, with a checkbox, which I would like to be unchecked initially. According to the documentation:
--------
$form->checkbox($name, $value, $isChecked, $tagAttributes)

Outputs a checkbox. The $isChecked boolean controls whether the checkbox is initially checked or not.
--------

So I've tried...
false
'false'
0
'0'
''
...

No matter what I pass in that slot, the box appears checked. I'm probably overlooking something obvious, but if someone can give me a whack with a clue-by-four, I'd be grateful.

Thanks!

landollweb
 
landollweb replied on at Permalink Reply
landollweb
Anyone out there building custom form blocks with checkboxes?
moosh replied on at Permalink Reply
moosh
I've got the same problem...

Any idea ?

Thanks

moosh
chameleondesign replied on at Permalink Reply
chameleondesign
same problem. Is this feature bust on concrete5 or are we doing something wrong?
hutman replied on at Permalink Reply
hutman
I tested it just in a page, and it seems to be working for me.

<form method="post" action="/">
<?php 
$fh = Loader::helper("form");
echo "Test";
echo $fh->checkbox("test_me", 'yes', 1);
echo $fh->checkbox("test_you", 'no', 0);
echo $fh->submit("go", "go");
?>      
</form>


That was with version 5.6.0.2, so possibly outdated, but I doubt it. I'm guessing that it's something else in your code. I know that if the variable exists and it's in the request array somehow (which might happen with opening a block form) then it will use that instead.
VPenkov replied on at Permalink Reply
VPenkov
You can also try this:
http://www.concrete5.org/community/forums/customizing_c5/extended-f...

This seems to do the trick for the other guy.

Also, here's the function:
/*@param string $isChecked "Checked" value (subject to be overridden by $_REQUEST). Checkbox is checked if value is true (string). Note that 'false' (string) evaluates to true (boolean)!
    */
   public function checkbox($key, $value, $isChecked = false, $miscFields = array()) {
      $id = $key;
      $_field = $key;
      if ((strpos($key, '[]') + 2) == strlen($key)) {
         $_field = substr($key, 0, strpos($key, '[]'));
         $id = $_field . '_' . $value;
      }
      if ($isChecked && (!isset($_REQUEST[$_field])) && ($_SERVER['REQUEST_METHOD'] != 'POST')) {
         $checked = true;
      } else if ($this->getRequestValue($key) == $value) {
         $checked = true;
      } else if (is_array($this->getRequestValue($key)) && in_array($value, $this->getRequestValue($key))) {
         $checked = true;

Mind the comments.