If we have two submit buttons and want to detect which one is pressed then simply use post method i.e. $this->request->data.
<?php echo $this->Form->create(false); ?>
<?php echo $this->Form->text('input'); ?>
<?php echo $this->Form->submit('Yes', array('name' => 'submit1')); ?>
<?php echo $this->Form->submit('No', array('name' => 'submit2')); ?>
<?php echo $this->Form->end(); ?>
When form is submit then print the response and see the array.
when the "Yes" button is clicked:
array(
'submit1' => 'Yes',
'input' => 'test'
)
when the "No" button is clicked:
array(
'submit2' => 'No',
'input' => 'test'
)
To check which button was clicked:
if (isset($this->request->data['submit1'])) {
// yes button was clicked
} else if (isset($this->request->data['submit2'])) {
// no button was clicked
}
0 Comment(s)