View Single Post
  #4 (permalink)  
Old 05-15-2008, 02:35 PM
jasonw jasonw is offline
Junior Member
 
Join Date: May 2008
Posts: 10
Default

Believe it or not, this is actually much easier than it sounds.

If you have multiple submit buttons with the same name but different values, the form will automagically assign the value of the pressed button to that name.

So...

Code:
<FORM action="./" method="post">
<INPUT type="text" name="whatever">

<INPUT type="submit" name="formsubmit" value="one">
<INPUT type="submit" name="formsubmit" value="two">
<INPUT type="submit" name="formsubmit" value="three">
</FORM>

And....


PHP Code:
$submit $this->_request->getPost('formsubmit');

switch(
$submit) {
case 
'one':
   
// button one was pressed
   
break;
case 
'two':
   
//button two was pressed
   
break;
case 
'three':
   
// button three was pressed
   
break;
}




Sorry I'm not specifically using Zend_Form in my examples, I rarely use it myself. But, this is just an example.


One major disclaimer, however:

If you are submitting the form through an Ajax request, this may be iffy!!
I know for a fact that Prototype's Form.serialize() can't handle which one was pressed.
Reply With Quote