I have following checkbox
<td><?php echo $this->Form->checkbox('purchase_owner_occupied', array('hiddenField' => false));?>Purchase owner occupied </td>
<td><?php echo $this->Form->checkbox('purchase_an_investment_property', array('hiddenField' => false));?>Purchase an investment property </td>
<td><?php echo $this->Form->checkbox('purchase_land', array('hiddenField' => false));?>Purchase Land </td>
When I check then then the post value is like below
[purchase_owner_occupied] => 1
[purchase_an_investment_property] => 1
[purchase_land] => 1
Let say I need to edit those information to uncheck purchase_land, when I uncheck purchage_land
and check remaining 2 the post value will be as below
[purchase_owner_occupied] => 1
[purchase_an_investment_property] => 1
I need to check all these value with extrastep code
if ($purchase_owner_occupied==1) { // }
Isn't there are way so that unchecked field will have 0
value like below?
[purchase_owner_occupied] => 1
[purchase_an_investment_property] => 1
[purchase_land] => 0
You need to use different values of 0/1 and also the hiddenField
parameter is required:
<td><?php echo $this->Form->checkbox('purchase_owner_occupied', array('value' => 'y', 'hiddenField' => 'n')); ?>Purchase owner occupied</td>
<td><?php echo $this->Form->checkbox('purchase_an_investment_property', array('value' => 'y', 'hiddenField' => 'n')); ?>Purchase an investment property</td>
<td><?php echo $this->Form->checkbox('purchase_land', array('value' => 'y', 'hiddenField' => 'n')); ?>Purchase Land</td>
Example output if I just select the second checkbox:
array(
'purchase_owner_occupied' => 'n',
'purchase_an_investment_property' => 'y',
'purchase_land' => 'n'
)