micmania1 Posted March 9, 2007 Share Posted March 9, 2007 How is this done? Link to comment https://forums.phpfreaks.com/topic/42033-solved-validating-radio-buttons/ Share on other sites More sharing options...
Barand Posted March 9, 2007 Share Posted March 9, 2007 Would you care to be a little more specific? Link to comment https://forums.phpfreaks.com/topic/42033-solved-validating-radio-buttons/#findComment-203863 Share on other sites More sharing options...
micmania1 Posted March 9, 2007 Author Share Posted March 9, 2007 ok theres 2 options, yes and no. Do I use empty(), isset(), or is there a special function? I've never validated a radio button before. Link to comment https://forums.phpfreaks.com/topic/42033-solved-validating-radio-buttons/#findComment-203872 Share on other sites More sharing options...
Barand Posted March 9, 2007 Share Posted March 9, 2007 Method 1 Set one of the buttons "checked" by default so a value is always posted Method 2 If neither selected then no value posted <?php if (isset($_POST['action'])) { if (!isset($_POST['myrb']) ) { echo "Please select Yes or No" ; } else { echo 'You selected ' . $_POST['myrb'] ; } } ?> <form method='post'> Yes <input type='radio' name='myrb' value='Yes'><br/> No <input type='radio' name='myrb' value='No'><br/> <input type='submit' name='action' value='Submit'> </form> Method 3 Have hidden field before the radio buttons on the form with same name then it's value is sent if no button selected <?php if (isset($_POST['action'])) { if ($_POST['myrb'] == 0 ) { echo "Please select Yes or No" ; } else { echo 'You selected ' . $_POST['myrb'] ; } } ?> <form method='post'> <input type='hidden' name='myrb' value='0'> Yes <input type='radio' name='myrb' value='Yes'><br/> No <input type='radio' name='myrb' value='No'><br/> <input type='submit' name='action' value='Submit'> </form> Link to comment https://forums.phpfreaks.com/topic/42033-solved-validating-radio-buttons/#findComment-203886 Share on other sites More sharing options...
micmania1 Posted March 9, 2007 Author Share Posted March 9, 2007 Thanks a lot for the help. Spent about an hour searching online and couldn't find anything. It kept coming up with javascript. Link to comment https://forums.phpfreaks.com/topic/42033-solved-validating-radio-buttons/#findComment-203894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.