AdRock Posted November 12, 2014 Share Posted November 12, 2014 Whenever I try and post a form with radio buttons like this <input type="radio" name"whatever" value="0"> and I do a var_dump($_POST) it always shows array(11) {["whatever"]=> string(2) "on" } but this works and will display 1 in the var_dump <input type="radio" name"whatever" value="1"> Why is this. I need the value set to 0 because that's the value going into the database. I don't really want to do a str_replace just to replace "on" with "0" Quote Link to comment Share on other sites More sharing options...
Solution tryingtolearn Posted November 12, 2014 Solution Share Posted November 12, 2014 might just be a typo but do you have a = sign for name in the real code? <input type="radio" name"whatever" value="0"> just a thought because this works <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { var_dump($_POST); } ?> <form action="index.php" method="POST"> <input type="radio" name="whatever" value="0"> <input type="radio" name="whatever" value="1"> <input type="radio" name="whatever" value="2"> <input type="submit" name="submitted" value="Search" /> </form> but this doesnt <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { var_dump($_POST); } ?> <form action="index.php" method="POST"> <input type="radio" name"whatever" value="0"> <input type="radio" name="whatever" value="1"> <input type="radio" name="whatever" value="2"> <input type="submit" value="Search" /> </form> Quote Link to comment Share on other sites More sharing options...
AdRock Posted November 12, 2014 Author Share Posted November 12, 2014 Yes. That was a typo and I've narrowed it down to a form class I use that generated form elements. Actually writing the html markup does work but my form class seems to drop the zero value. I might have to set the form values to yes/no and then convert that to a 0/1 before it goes into database. Anyway thanks for your help. At least it helped my identify the problem Quote Link to comment Share on other sites More sharing options...
tryingtolearn Posted November 12, 2014 Share Posted November 12, 2014 Doesn't seem like you should have to do that but hard to tell without seeing the class. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.