Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2008, 10:01 AM
Junior Member
 
Join Date: Mar 2008
Posts: 7
Default multiple submit button

hello,

I'm using a form with 2 submit buttons and I want to know witch one was clicked on.
I found on google that you can use de methode isChecked(), but this always return false:
PHP Code:
$form->add->isChecked() 
Someone how know what I'm doing wrong?

greets,
BlaCK ErrOR
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-08-2008, 10:18 AM
Junior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 8
Default

Without seeing the rest of your code, that's fairly difficult to say.

Quote:
isChecked() checks the submitted value against the label in order to determine if the button was used.
What do you have set as the name, value and label for your two buttons?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-08-2008, 10:41 AM
Junior Member
 
Join Date: Mar 2008
Posts: 7
Default

PHP Code:
$form = new Custom_forms_AddMenuItem(); 
PHP Code:
class Custom_forms_AddMenuItem extends Zend_Form {
    
public function 
__construct()  { 

// input box
  
$add = new Zend_Form_Element_Submit('add');
$add ->setLabel('Save item')
       ->
setValue('Add');
             
$addOther = new Zend_Form_Element_Submit('addOther');
$addOther ->setLabel('Save and add other item')
           ->
setValue('Add other');

$this->addElements(array($name$parent$contAction$linkVar$menuPerm$add$addOther));

// decorators
}


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-15-2008, 02:35 PM
Junior Member
 
Join Date: May 2008
Posts: 12
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:55 PM.