By radhika.w on
hi there...
i wanted to know a way for handling multiple submit buttons and their click events..
here i have a form where i have two buttons ... search and save...
When the user clicks on search, the page is redirected to myform/search
and else, myform/save ...
I have been trying to use the condition:
<?php
if($form_state['values']['search'] == 'Search'){
$form_state['redirect'] = 'myform/search/'.$form_state['values']['compname'];
}
$form_state['redirect'] = 'myform/save/'.$form_state['values']['compname'].'/'.$form_state['values']['street'].'/'.$form_state['values']['locality'].'/'.$form_state['values']['city'].'/'.$form_state['values']['pin'].'/'.$form_state['values']['state'].'/'.$form_state['values']['country'].'/'.$form_state['values']['description'].'/'.$form_state['values']['headedby'].'/'.$form_state['values']['contactperson'].'/'.$form_state['values']['phone'].'/'.$form_state['values']['email'].'/'.$form_state['values']['website'].'/'.$form_state['values']['branch'].'/'.$form_state['values']['category'];
}
?>
This jus doesnt go in the if loop and runs out and redirects to the myform/save page ...
Can you help?!?!
Thanks,
Radhika
Comments
Hi radhika, I've found you
Hi radhika,
Try:
Your two buttons should have different #value names - I think you're ok because you've got 'Search' and 'Save'. But in the case where they have the same name -- eg two 'save' buttons, you need to give them seperate names with the #name property.
does not work :(
hi..
thanks for the reply....
But it does not help...
It gives me exactly the same results as before ...
Radhika
You have to use an 'else'
You have to use an 'else' clause.
Why are you actually doing such a redirect when saving? It's a lot easier (and the URL is a lot cleaner) when you perform the actual save in the
_submit()function and you redirect to a nice OK page after the save has been completed.thanks for the idea!
hi thanks for the idea .. :)
i had actually thought about it ...
but got flown into the multiple submit buttons problem !!
i will try that and let u know
thanks again,
radhika
Thanks it Works!
thanks j.somers .... for that idea...
It really helped me to sor all my functions..
Now i can edit delete and update data through the same form...
Thanks a million!!!
Enjoy,
Radhika
Multiple submit buttons with different redirects
There is a bit more to adding multiple submit buttons in Drupal than at first glance. I didn't find an article that covered all the elements I needed, so here is a condensed version of how I did it.
1) You need to add the buttons and call a different function depending on which button is clicked, this is fairly easy and there are a number of tutorials about this online. Basically this is how you do that.
In the form_alter function of your Drupal module you can add lines like this to add new buttons.
You have to add 'node_form_submit' to the default submit button if you also want to add a second function call on the same button.
2) For the default button I did a redirect to a URL with parameters and using the node ID. Note the use of array was necessary to avoid URL mashing (probably not the technical term).
The array is needed to avoid the URL being mashed.
3) For Button 2 I did a redirect to a URL without any parameters using the node ID.
References:
http://drupal.org/node/247585