...

View Full Version : multiple buttons on form



Bengal313
09-15-2003, 08:40 PM
How can I have a single form that has multiple buttons. And since a form has only 1 action option (url) How do I make each button go to different urls?

raf
09-15-2003, 08:54 PM
just add another value to each submitbutton.

you give all submitbuttons the same name, but a differnt value. Then in the page where the form is posted to, you use a switch on $_POST['submitoption'] or whatever you call the buttons (all the same name !) like


switch ($_POST['submbutton']) {
case "1":
header("Location: http://".$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
."/actionpage1.php");

break;
case "2":
header("Location: http://".$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
."/actionpage2.php");

break;
case "3":
header("Location: http://".$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
."/actionpage3.php");
break;
}

Bengal313
09-15-2003, 09:06 PM
The part you posted with the url location do I put that somewhere in the form where the buttons are or do I put that on the resulting pages? Thanx very much

raf
09-15-2003, 09:16 PM
OK. Say that (part of) your fotm looks like this


echo("<form name=\"actionform\" action=\"switchpage.php\" method=\"post\">");

echo("<input type=\"submit\" name=\"submit\" value=\"Home\" />");
echo("<input type=\"submit\" name=\"submit\" value=\"Delete\" />");
echo("<input type=\"submit\" name=\"submit\" value=\"Insert\" />");

echo("</form>");


Then you will have something like this in "switchpage.php"


switch ($_POST['submbutton']) {

case "home":

header("Location: http://".$_SERVER['HTTP_HOST']

.dirname($_SERVER['PHP_SELF'])

."/home.php");



break;

case "delete":

header("Location: http://".$_SERVER['HTTP_HOST']

.dirname($_SERVER['PHP_SELF'])

."/delete.php");



break;

case "insert":

header("Location: http://".$_SERVER['HTTP_HOST']

.dirname($_SERVER['PHP_SELF'])

."/insert.php");

break;

}

Bengal313
09-16-2003, 02:34 AM
Thank you very much. This will work fine php 4 right!

raf
09-16-2003, 11:55 AM
I suppose. Depending on version and settings, you might need to replace $_SERVER by $HTTP_SERVER_VARS

But just try it out and see what happens ...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum