xkyogre Posted July 10, 2007 Share Posted July 10, 2007 I have a form that needs to be checked. It contains 4 radio boxes a submit button and 4 different hidden fields. How do I get my php script to check if a radio box has been selected and tell the user to check a radio box if he hasn't? The script I am currently using doesn't work; if the user chacks some thing then it proceeds as usual, but if it is left blank then the program freezes up and nothing is displayed apart from the stuff outside the <?php?> tags. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 10, 2007 Share Posted July 10, 2007 Do you think we could see your code that you have? Dont forget to enclose it in tags(without the spaces) However, to answer what i think is your question, say you had the following radio button: [code] <input type='radio' name='yourfield' value='option1' /> Then to check if this option had been selected, you would use: <?php if($_POST['yourfield'] = 'option1'){ //option1 selected } ?> Of course, if your form method was get, use the $_GET array. Quote Link to comment Share on other sites More sharing options...
xkyogre Posted July 11, 2007 Author Share Posted July 11, 2007 <?php foreach($_POST as $field => $value){ if($field == 'crime'){ if($value == " ") { $blob = 1; } } } if($blob == 1) { #redisplay form } else{ #show results } 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.