Reputation: 5256
foreach ($statuses as $key=>$value) {
echo $this->Form->control('Filter.statuses['.$key.']', array(
'type' => 'checkbox',
'value' => $key,
'label' => $value,
));
}
Unexpected field 'Filter.statuses[1' in POST data
Unexpected field 'Filter.statuses[2' in POST data
Unexpected field 'Filter.statuses[3' in POST data ...
$this->Form->unlockField('Filter.statuses');
$this->Form->unlockField('Filter.statuses[]');
If I remove the Filter.
prefix, the errors are gone and I no longer need the unlockField()
call.
Upvotes: 0
Views: 719
Reputation: 60453
You're not supposed to use brackets in the field name, the form helper doesn't support that. If you ever need an unconventional name that the form helper doesn't support, then use the name
option to specify it, while passing a compatible field name to the control()
method's first argument.
Use the dot syntax all the way:
echo $this->Form->control("Filter.statuses.$key", /* ... */);
That way the form helper will be able to secure the fields, and create proper HTML name attribute values like Filter[statuses][1]
.
Upvotes: 2