Problem with FormHelper->checkbox function

Permalink 0 1 Browser Info Environment
If you have a form with checkboxes and you want to set the checkboxes "checked", you use the third value of the function and set it to true.

for example:

$form->checkbox('myfield', '1', ($anothervar == '1'));


Now you make a POST on the page which contains the created checkbox. The third value is IGNORED! Also if it is set to "true".

This happens because of this line:

if ($isChecked && (!isset($_REQUEST[$_field])) && ($_SERVER['REQUEST_METHOD'] != 'POST')) {


and I think this is wrong. We should check is the value set via the request, if not then use the set value from the 3rd argument.

Don't know why we check the request method here. On other functions from the FormHelper this is handled in another way.

For example look at the "hidden()" function on the FormHelper.


Status: New
scalait
andrew replied on at Permalink Reply
andrew
I'm not sure I understand. As with all the other form helpers, if something is posted, it takes precedence over the original setting. That's so that you can set something once and then post a form and the form retains its state.

We only do this with POST however because checkboxes don't include their state if they're unchecked in GET requests, and so we'd never know if you were submitting the form or had just gone to the page for the first time.

concrete5 Environment Information

---

Browser User-Agent String

Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19