Just upgraded to v9.0.1 and after spending some time trying to figure out how the Mail Service works, if it really works in v9, I’m wondering if I’m imagining things or there’s a problem somewhere.
I want to submit a form from a block (not in Dashboard) with a checkbox, e.g.
echo $form->checkbox('agree', 1, '0');
echo $form->label('agree', t('I agree'));
and I read the POST value in a block controller:
$agree = $data['agree'];
but that $agree value is always 1 regardless whether the checkbox is selected or not. That is so simple yet it drives me nuts that I can’t figure out where the problem is. This exact code works in the Dashboard when I save forms with checkboxes. But it doesn’t work in the front end. What am I missing here?
$agree = isset($data['agree']); has no effect
I’ve just pasted exactly the same code into a v8 form and
$agree = $data['agree']; <- this returns NULL regardless of being checked
$agree = isset($data['agree']) ? 1 : 0; <- this returns always 0 regardless of being checked
$agree = !is_null($data['agree']) ? 1 : 0; <- this returns always 0 regardless of being checked
What’s going on with the checkboxes in Concrete?
A textual ‘0’ is a boolean true.
Sorry, friends, it’s one of those days when the error looks so stupid that it can’t be possible, you have to look for the most stupid own mistake. I’ve just spent 2 days looking for it. Then when I thought I’ve exhausted all options, I’ve raised the issue.
As it turned out, I forgot I was using ajax to send the form, and the JS was taking the
$('#agree').val(); instead of
$('#agree').is(':checked') ? 1 : 0; . Sorry for false alarm. Feel so stupid…