Multiple redirects for multiple submit buttons

radhika.w - January 7, 2009 - 11:05

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

Hi radhika, I've found you

jeremy_a - January 7, 2009 - 11:32

Hi radhika,

Try:

if($form_state['values']['clicked_button']['#value'] == 'Search'){
...

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 :(

radhika.w - January 7, 2009 - 12:14

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'

j.somers - January 7, 2009 - 14:17

You have to use an 'else' clause.

<?php
$a
= 1;
if (
$a == 1) {
 
$b = 2;
}
$b = 3;
print
$b; // This will always print out the number '3'.

$a = 1;
if (
$a == 1) {
 
$b = 2;
}
else {
 
$b = 3;
}
print
$b; // This will print out the number '2'.
?>

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!

radhika.w - January 9, 2009 - 12:42

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!

radhika.w - January 13, 2009 - 07:37

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

 
 

Drupal is a registered trademark of Dries Buytaert.