PDA

View Full Version : best way to submit form with multiple buttons


o0O0o.o0O0o
04-10-2008, 02:12 AM
hi guys n gals (if any :D),


I want to know which is the best and easiest way to submit a form , if i have multiple buttons




e.g i have different php files e.g 10 and i have 10 buttons on the website
i wan to use only one form so that different button goes to diff php page


and if i want to invoke different functions from same php page how can i post variables with different buttons but only one form

Inigoesdr
04-10-2008, 02:38 AM
Give them different names, and check for each when the form is posted. Only the one clicked should exist in $_POST.

o0O0o.o0O0o
04-10-2008, 03:18 AM
Give them different names, and check for each when the form is posted. Only the one clicked should exist in $_POST.


Did you mean different name of buttons like

<input type = button name = a1 value = form1>
<input type = button name = a2 value = form1>
<input type = button name = a3 value = form1>


so if i press thired button

$_POST['a3'] = 1


What bout if i wan to go to diff php page

Can u explain with e,g

GO ILLINI
04-10-2008, 04:46 AM
you could have a relocate.php page, then by the button pressed go to different pages. Or you could javascript.
The button would call a function a1(),a2(),... and that will change the "action" of the form and then submit the form.


JS functions:

a1() {
document.form1.action = "a1.php";
document.form1.submit();
}

button:
<input type="button" onclick="a1()" value="a1">

NOTE: I didn't test this code, it is just an example. I probably missed some crazy JS syntax that I've forgotten over the years...

-Adam