Php – How to detect which submit button was pressed on a Zend Framework form

form-submitPHPzend-form

I have a Zend Framework form that has two submit buttons

$changes = new Zend_Form_Element_Submit('save_changes');
$changes->setLabel('Save Changes');

$delete = new Zend_Form_Element_Submit('delete');
$delete->setLabel('Delete');

Which renders HTML like such:

<input type="submit" name="save_changes" id="user_save_changes" value="Save Changes" >
<input type="submit" name="delete" id="user_delete" value="Delete" >

In the controller, how do I determine which button the user pressed?

Best Answer

In your case you should just be able to check

if(isset($_POST['save_changes'])
// or
if(isset($_POST['delete'])

Since only the value of the clicked button will be submitted.

Usually you give both buttons the same name (e.g. action) and then set the value to the action you want to perform. Unfortunately that doesn't work very well with IE. Check this page for more information about different solutions for multiple submit buttons.