davidcowler
asked on
How can I have multiple buttons in HTML that POST to PHP?
Hi Experts
I'm sure this question is as old as the hills but I haven't been able to find an exisitng suitable answer on EE.
I have a HTML page that has two buttons, each of which I want to go to different PHP scripts. I need the form method to POST some variables to the script, so I am using buttons instead of just graphics and/or text.
I understand that the buttons have to be of the 'submit' type but can only make them all do the same thing!
This particular issue has two buttons, as mentioned, but I can see that I might need to have another page in my project that has more than 2 buttons.
How can I achieve this in PHP, or maybe Javascript?
Thanks
Dave
I'm sure this question is as old as the hills but I haven't been able to find an exisitng suitable answer on EE.
I have a HTML page that has two buttons, each of which I want to go to different PHP scripts. I need the form method to POST some variables to the script, so I am using buttons instead of just graphics and/or text.
I understand that the buttons have to be of the 'submit' type but can only make them all do the same thing!
This particular issue has two buttons, as mentioned, but I can see that I might need to have another page in my project that has more than 2 buttons.
How can I achieve this in PHP, or maybe Javascript?
Thanks
Dave
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, I agree, like my first suggestion, just not as elaborate as yours ;)
Here is the plain old HTML example, appended to the action script that processes its inputs. HTH, ~Ray
<?php // RAY_many_submit_buttons.php
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL;
// SHOW HOW TO PROCESS A FORM THAT HAS MORE THAN ONE SUBMIT BUTTONS
// HAS THE FORM BEEN POSTED?
if (!empty($_POST["my_submit_button"]))
{
switch ($_POST["my_submit_button"])
{
case "A" : echo "YOU ENTERED 'A' "; break;
case "B" : echo "YOU ENTERED 'B' "; break;
case "C" : echo "YOU ENTERED 'C' "; break;
default : echo "NONE OF A, B OR C";
}
}
// END OF PHP PROCESSING - PUT UP THE FORM
?>
<form method="post" />
<input name="my_submit_button" type="submit" value="A" />
<input name="my_submit_button" type="submit" value="B" />
<input name="my_submit_button" type="submit" value="C" />
</form>
ASKER
Hi guys
Thanks for those suggestions. I can actually see me using both of these in the project I'm working on so I'm going to split the points between you.
Thanks :)
Dave
Thanks for those suggestions. I can actually see me using both of these in the project I'm working on so I'm going to split the points between you.
Thanks :)
Dave
Thanks, Dave. Give more of the points to Michel - his answer was there first. Best, ~Ray
ASKER
Sorry, too late!
No problem :)