0
echo "<form method="POST" action="' . htmlspecialchars($_SERVER["PHP_SELF"]) . '"><button type='submit'>Yes</button></form>";
echo "<form method="POST" action="' . htmlspecialchars($_SERVER["PHP_SELF"]) . '"><button type='submit'>No</button></form>";

I want to make 2 buttons, but not sure how to make them send $_POST["yes"] and $_POST["no"].

1
  • why two forms with one buttons? You could just use one form with two submit buttons having different value attributes. Commented Jun 9, 2014 at 9:52

1 Answer 1

1

The normal way would be to use a single form with two submit buttons:

<form action="" method="post">
    <input type="submit" name="answer" value="Yes" />
    <input type="submit" name="answer" value="No" />
</form>

To see it in action, add:

var_dump($_POST);

to your PHP. You should see that only the button you clicked on is sent.

Sign up to request clarification or add additional context in comments.

2 Comments

Didn't knew you could add 2 submit buttons to a form.
Still, how do I get access to the answer? Like $_POST["value"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.