0

Trying to get a value from this checkbox but it's not working..

Should be a simple yes or no .. however nothing is happening .. always defaults to the else statement.

<form id="edit_donor_form" action="<?php echo $_SERVER['PHP_SELF']; ?>"
      method="post" name="switch">
  <label class="switch">
    <input type="checkbox" name="switchq" value="Yes" >
  </label>
  <input name="submit" type="button" value="submit" />
</form>
<?php
   if(isset($_POST['submit']) && $_POST['switchq'] == 'Yes') {
     echo "Hover On.";
   }
   else {
     echo "Hover Off";   
   }    
?>
1
  • 2
    Change your submit input from type="button" to type="submit" this may help. Commented Oct 18, 2013 at 17:58

2 Answers 2

2

Because your form not has submit botton, the input type that you used was button you need to change it to submit

<input name="submit" type="submit" value="submit" />
Sign up to request clarification or add additional context in comments.

1 Comment

+1 anyway. Since both answers were almost the same, I deleted mine :)
0

If You dont't want change input type="button" to type="submit", You can add:

<input name="submit" type="button" value="submit" onclick="document.getElementById('edit_donor_form').submit();" />

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.