shadowayex Posted June 9, 2008 Share Posted June 9, 2008 Alright, so I learned about check boxes and radio buttons a long time ago from w3schools.com. But I never used them in forms. I'm currently developing a site that is going to have a nice account settings page for the user that will use both. Let's say I had this little bit of HTML: Gender: <input type="radio" name="gender" value="male" /> Male <input type="radio" name="gender" value="female" /> Female<br />Activate DST Edit <input type="checkbox" name="dst" value="yes" /><br /> In order to get the PHP to read those, would it just use the regular $_POST method? $gender = $_POST['gender'];$dst = $_POST['dst']; Would that do it? Or would the fact that both radio buttons are named gender interfere? And what will the $dst variable be if the check box is left unchecked? Link to comment Share on other sites More sharing options...
Ingolme Posted June 9, 2008 Share Posted June 9, 2008 Yes.In the first case $_POST['gender'] will return the selected value.In the second case, $_POST['dst'] will return "yes" if selected and an empty string if it's not selected.I usually use strlen() to evaluate checkbox values: if(strlen($_POST['dst'])) {// Some code here} else {// Some other code here} Though checking for the value also works: if($_POST['dst'] == "yes") {// Some code here} else {// Some other code here} Link to comment Share on other sites More sharing options...
shadowayex Posted June 9, 2008 Author Share Posted June 9, 2008 Ok, I understand now. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.