I am adding a checkbox to my form using:
$fieldset->addField($value, 'checkbox', array(
'label' => $label,
'name' => $value,
'checked' => false,
'onclick' => "",
'onchange' => "",
'value' => $value,
'disabled' => false,
'tabindex' => 1
));
Then in my controller I am doing:
if (isset($this->post[$value]))
{
$webCategory = $this->post[$value];
if ($webCategory != '') {
Mage::log("Syncing: " . $webCategory);
}
}
$this->post is the Mage::app()->getRequest()->getPost() from the page. $value contains the id of the checkbox (all the data is dynamic so I have posted snippets).
The issue I have is that the checkbox values are always getting logged even when I don’t tick them. I always thought checkboxes weren’t posted unless they were ticked. Am I losing it or does Magento do something odd?
First check your browser: What data get POSTed? The network tab of your browser’s debugger (e.g. Firebug for Firefox) will tell you. Are the checkboxes data in there?
Second, check the HTML: Are the checkbox names defined multiple times? That might be the reason for them to show up in your POST data.