php - Multiple choice form action depend on choice
I have this
Multiple choice form, the button goes to a certain page when clicked. However, I want it to run something specific when the page is reached. So if someone submits the form with Orc Camp selected, they would go through one set of code, but if Orc City was selected they would go through another.
I know how to do this in the same page (IF isset post etc) but I don't know how to link the button result to another page!
EXAMPLE
Orc Camp is selected, button is pressed and user goes to different page, lets call it battle.php
The page will echo "You have attacked Orc Camp" if Orc Camp was selected.
If Orc Village was selected, it will again go to battle.php but will echo "You have attacked Orc Village"
Sorry if I haven't described the problem well enough
Answer
Solution:
If you are using a form like:
OR
All the values that are within a
<form></form>
tag are automatically saved in $_POST. An easy tip I use to see which values get passed is just usevar_dump($_POST)
to print all the data to the screen that was saved in $_POST.Example form on battle.net:
The action is now set to go to battle page, so now you just need to get the data on the battle page like:
The only thing you need to do now, is add error handling and your logic etc.. to the battle page.