Page 1 of 1

calling two Actions in a form

Posted: Sat Apr 23, 2005 10:26 am
by gen23
Hi,

I am creating a php program with an HTML integration. Within my HTML code, I called two buttons... my question is, how can I call two different actions or page using a single form? Is this correct?

Code: Select all

<form method = &quote;POST&quote; action = &quote;/module/Default/action/Add&quote; , action = &quote;/module/Default/action/Search&quote;> 

<input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;submit&quote;> 
<input type=&quote;submit&quote; name=&quote;search&quote; value=&quote;search&quote;> 
<input type= &quote;text&quote; name=&quote;search&quote;>
Thank you.... :oops:

Posted: Sat Apr 23, 2005 10:33 am
by timvw
you can have only one "action" per form.

but as you already noticed, you can have multiple submit buttons, with various names/values...

so, for example:

Code: Select all

<form type=&quote;post&quote; action=&quote;foo.php&quote;>
<input type=&quote;submit&quote; name=&quote;action&quote; value=&quote;add&quote;/>
<input type=&quote;submit&quote; name=&quote;action&quote; value=&quote;search&quote;/>
</form>
if the user than clicks on the add button, you will have $_POST['action'] == 'add'. And if he clicks on the search button, $_POST['action'] will equal 'search'

Posted: Sat Apr 23, 2005 10:53 am
by gen23
Does that mean that my form would look like this--> <form method="POST"> Since my two buttons will lead to a different page and placing a certain page on the action might become confusing?

Posted: Sat Apr 23, 2005 3:12 pm
by hawleyjr
Untested:

Code: Select all

<script Language=&quote;Javascript&quote;>

function goToPage1(){
  
 doc = eval(&quote;document.form1&quote;);
 doc.action = &quote;/module/Default/action/Add&quote;;
 doc.submit();
 
}
function goToPage2(){
  
 doc = eval(&quote;document.form1&quote;);
 doc.action = &quote;/module/Default/action/Search&quote;;
 doc.submit();
 
}
</script>
<form name=&quote;form1&quote; method = &quote;POST&quote;> 
 
<input type=&quote;submit&quote; name=&quote;submit&quote; value=&quote;submit&quote; onclick=&quote;goToPage1(); return false;&quote;> 
<input type=&quote;submit&quote; name=&quote;search&quote; value=&quote;search&quote; onclick=&quote;goToPage2(); return false;&quote;> 
<input type= &quote;text&quote; name=&quote;search&quote;>

Posted: Mon Apr 25, 2005 3:10 am
by duk
i was need this to eheehe...

but if you don't want to use javascript and you want to preform two actions with one button form, use some php function to pass information to another page.. for example...


<form method=post action=1111.php>

-----------------------------

second action

Code: Select all

function 2_action() {

header (" location: page?value=xx ");

}