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!
--------
$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!
Anyone out there building custom form blocks with checkboxes?
I've got the same problem...
Any idea ?
Thanks
moosh
Any idea ?
Thanks
moosh
same problem. Is this feature bust on concrete5 or are we doing something wrong?
I tested it just in a page, and it seems to be working for me.
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.
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.
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:
Mind the comments.
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;
Viewing 15 lines of 21 lines. View entire code block.
Mind the comments.