Forum Moderators: coopster

Message Too Old, No Replies

Multiple submit buttons

To POST data to multiple pages.

         

eggy ricardo

3:13 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



Hiya guys,

I am building my 3rd or 4th fairly basic PHP and MySQL site, and in building a content management system the need has arised for the following:

A form which has two submit (or similar) buttons at the bottom. What i want is when buttonA is pressed, the form POSTs the data to buttonA.php, and when buttonB is pressed, POST the data to buttonB.php and so on.

I am not sure how I can do this as as far as i know, where the form is POSTed to is defined in the action rather than the button itself. I am fairly new to this so if you could help i would be very grateful.

Cheers
Richard

ScottYardley

3:27 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



if(!isset($_POST['buttonA']){
do this
}
else if (isset($_POST['buttonB']{
do that
}

<form action="" method="post">
<input name="buttonA" type="submit" value="Click Me">
<input name="buttonB" type="submit" value="No, Click Me!">
</form>

ScottYardley

3:29 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



Opps errors in the above. This is better:

if(isset($_POST['buttonA'])){
do this
}
else if (isset($_POST['buttonB'])){
do that
}

<form action="" method="post">
<input name="buttonA" type="submit" value="Click Me">
<input name="buttonB" type="submit" value="No, Click Me!">
</form>

ScottYardley

3:36 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



If you absolutely need to result on two seperate pages you can use a hearder redirect.
To do this your POST variables would have to passed as a GET.

if(isset($_POST['buttonA']))
header("Location: buttonA.php?varA=".$A."&varB=".$B);

else if (isset($_POST['buttonB']))
header("Location: buttonB.php?varA=".$A."&varB=".$B);