Here is the code for my form:

  <form action = "index.php" method="post"> <!--the form is being submitted to the same page-->
  <button class="btn" name="button" onClick="submit()">Yes</button>
  <button class="btn btn-primary active" name="button" onClick="submit()">No</button>

And on the top of my index.php I have the following:

$refresh = $_POST['button'];

When I echo $refresh after I push the button, all I get is 0. Any idea of what I'm doing wrong?

Thanks in advance!

Member Avatar


1) I can't answer the question because I'm not sure what is in the index.php (code)

2) Do you have a database connected to your FORM?

I dont have a databse connected to my form, index.php is sending the button data to itself to be used as a variable

Based on my understanding, the form is submitted without any values provided.

even if I add values like "1" for on and "0" for off, it still always prints 0

Please do provide me with your submit() code.

Your button has no value so it will be empty. 2 things:

  1. Change your buttons to a submit and remove the javascript:

    <input type="submit" class="btn" name="submit_yes" value="Yes" />
    <input type="submit" class="btn btn-primary active" name="submit_no" value="No" />

Then change your PHP to get the value of the submit:

$refresh = $_POST['submit'];

@simplypixie I have think of the way also but as the name of the input is not the same, the post method can't get the value with only one $_post.

If really wish to do it this way, php code would be

    echo $_POST['submit_yes'];
    echo $_POST['submit_no'];