Nomax5 Posted July 28, 2006 Share Posted July 28, 2006 Suppose I have this form containing only radio buttons[code]<FORM action="nextpage.php" method="get"><input type="radio" name="form_gen" value="male"> Male<input type="radio" name="form_gen" value="female"> Female<input type="radio" name="form_car" value="bmw"> BMW<input type="radio" name="form_car" value="ford"> ford<input type="radio" name="form_car" value="jeep"> jeep<INPUT type="submit" value="Submit"> </FORM>[/code]if a visitor just clicks submit then off it goes with no data.Is there a simple way of not going to nextpage.php unless they’ve made their selection? Using isset or something?If I use a phpself thing then I always have a problem getting to nextpage.php with headers already been sent etc.Or do I have do the validation in nextpage.php then go back somehow?I have been searching for a solution but they all seem like overkill.Thanks Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/ Share on other sites More sharing options...
shocker-z Posted July 28, 2006 Share Posted July 28, 2006 Using PHP yes you would have to submit to a page and then validate.. If you look into Javascript or post a request in javascript forum then i'm sure that they can help you there :)RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65334 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 [code]<form action="nextpage.php" method="get"><input type="radio" name="form_gen" value="male" checked="checked">Male<input type="radio" name="form_gen" value="female">Female<input type="radio" name="form_car" value="bmw">BMW<input type="radio" name="form_car" value="ford" checked="checked">ford<input type="radio" name="form_car" value="jeep">jeep<input type="submit" value="Submit"> </form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65336 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 That's with sucky formatting. here is an updated version.[code]<form action="nextpage.php" method="get"><input type="radio" name="form_gen" value="male" checked="checked" />Male<input type="radio" name="form_gen" value="female" />Female<input type="radio" name="form_car" value="bmw" />BMW<input type="radio" name="form_car" value="ford" checked="checked" />ford<input type="radio" name="form_car" value="jeep" />jeep<input type="submit" name="submit" id="submit" value="Submit"> </form>[/code]You forgot to close those tags, and always name your submit buttons even if there just named submit,. Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65339 Share on other sites More sharing options...
Nomax5 Posted July 28, 2006 Author Share Posted July 28, 2006 ahh thanks for the formating I just typed that in the post, it's formatted correctly in the code honest ;)so what you're saying is that if I default them then they can't clear them so the form will be valid. The danger is that people may just take the defaults, although I could default to skoda :) Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65343 Share on other sites More sharing options...
hostfreak Posted July 28, 2006 Share Posted July 28, 2006 Add values to your defualts. Then check to see if the values are the ones of the defualt, if so don't allow it to be submitted. Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65361 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 PERFECT, hostfreak had a perfect idea, that would work like a miracle, I have to keep that in mind for later. Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65362 Share on other sites More sharing options...
Nomax5 Posted July 28, 2006 Author Share Posted July 28, 2006 I dont' understand hostfreak how do I add values to defaults? Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65410 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 value="none"then when it get's to the next page use something to validate thatif $_POST['whatever'] == "none']there was an errorsorry don't have time to format Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65413 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 sorry.ok you don't want people to be able to submit information without making a choice.Do this on hte page with the form roughly[code]<form action="nextpage.php" method="get"><input type="radio" name="form_gen" value="male" />Male<input type="radio" name="form_gen" value="female" />Female<input type="radio" name="form_gen" value="none" checked="checked" />None<input type="radio" name="form_car" value="bmw" />BMW<input type="radio" name="form_car" value="ford" />ford<input type="radio" name="form_car" value="jeep" />jeep<input type="radio" name="form_car" value="none" checked="checked" />None<input type="submit" name="submit" id="submit" value="Submit"> </form>[/code]None on your php page put this where you do validation if you append it to a screen, use exit, relocate, whatever you do to validate your formsthe setup is roughly like this[code]<?phpif ($_GET['formgen'] == "none" || $_GET['form_car'] == "none") {// You must select values for the 2 radio buttons. Whatever you do to validate here.}>>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65416 Share on other sites More sharing options...
Nomax5 Posted July 28, 2006 Author Share Posted July 28, 2006 Ohh I see radio buttons for none, I get it thanks matey really good answer Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65432 Share on other sites More sharing options...
kenrbnsn Posted July 28, 2006 Share Posted July 28, 2006 I just tried the following test:[code]<html><head><title>Test Form</title></head><body><?phpif (isset($_POST['submit'])) echo '<pre>' . print_r($_POST,true) . '</pre>';?><form method="post"><span style="display:none"><input type="radio" name="test" value="default" checked></span><br><input type="radio" name=test value="one"> One<br><input type="radio" name=test value="two"> Two<br><input name="submit" type="submit" value="test"></form></body></html>[/code]You'll notice this line:[code]<span style="display:none"><input type="radio" name="test" value="default" checked></span>[/code]The [b]<span style="display:none">[/b] hides the default radio button from being seen, but the value still gets transmitted.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65439 Share on other sites More sharing options...
Ninjakreborn Posted July 28, 2006 Share Posted July 28, 2006 That is an even better idea, I will have to keep that in mind. Quote Link to comment https://forums.phpfreaks.com/topic/15916-validating-a-simple-radio-button-form-solved/#findComment-65442 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.