php - Multiple choice form action depend on choice


I have this enter image description here

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!


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




If you are using a form like:

<form action="" method="POST">


<form action="" method="POST">

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

<form action="" method="post">
    <input type="radio" name="action" value="attack">Attack<br>
    <input type="radio" name="action" value="defend">Defend<br>

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.

People are also looking for solutions to the problem: php - Change currency depending upon IP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.