Stack Exchange
Submit button value not available in HTML / Twig / Bootstrap / PHP
I have a HTML / Twig / Bootstrap file with two buttons:
<form method="post" action="procuser.php">
    <div class="form-group">
        <label for="Details">Details:</label>
        <textarea class="form-control" rows="5" id="details" name="details">{{ details }}</textarea>
    </div>
    <button type="submit" name="button" value="submit" class="btn btn-default">Submit</button>
    <button type="submit" name="button" value="cancel" class="btn btn-default">Cancel</button
    <br><span class="err">{{ err }}</span>
</form>

Then in PHP, I check whether the form was submitted / cancelled using the checks:
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    if (isset($_GET["button"]) && $_GET["button"] == "submit")
    {
        if (postData(input("details"))) // <- never reaches here?
            header("success.php");
    }
    else
        header("menu.php");
}        

But the submit button does not work and I always get redirected to the menu.

I would make to different forms, one with user input and submit button and other with cancel buttom

Your form method is POST but you check for $_GET["button"]

I don't anything about twig but I do know you're submitting the form with POST and try to get the values with GET. That's not gonna work. Try $_POST[...] instead.

@fusion3k why don't you post that as an answer...? Looks like the issue here...

@icecub why don't you post that as an answer...? Looks like the issue here...

@devlincarnate actually, default form method is GET and button of type "submit" are posted

@webeno Because in this case I know it's causing an issue but I'm uncertain it will solve the problem completely. Aside from that, such simple problems are much faster answered with a comment and can still be turned into an answer if needed later on.

Yes, $_POST works fine (I'm not sure what devlin is saying).  My PHP is rusty :(

@tyebillion try replacing your $_GET with $_POST in your PHP and see if it makes a difference, then let us know by editing your original question pointing out what you edited for clarity (and especially as there is already an answer on it)...

Because you used method="post" for form in html. That's reason you can't get value of the button by $_GET
Change:
if (isset($_GET["button"]) && $_GET["button"] == "submit")

to:
if (isset($_POST["button"]) && $_POST["button"] == "submit")


According to this website: http://www.w3schools.com/tags/tag_button.asp

Note: If you use the <button> element in an HTML form, different
  browsers may submit different values. Use <input> to create buttons in
  an HTML form.

I recommend using
<input type="submit" name="button" value="submit" class="btn btn-default" />
<input type="submit" name="button" value="cancel" class="btn btn-default" />


I copied this but without the " /" characters at the end, nice one Russell!

if (isset($_GET["button"]) && $_GET["button"] == "submit")
in this code the event is not correct the user can click one button at a time so not possible to click two button at a time :)
use this 
if (isset($_GET["button"]) = "submit")
