What's Here?
Members: 132,672
Replies: 471,776
Topics: 73,151
Snippets: 2,541
Tutorials: 667
Total Online: 1,170
Members: 78
Guests: 1,092
Who's Online?
Loading. Please Wait...
Validating Radio Buttons
Validating Radio Buttons, Can't figure it out, I need some help
bphishin
19 Jun, 2007 - 10:57 AM
New D.I.C Head
Joined: 19 Jun, 2007
Posts: 5
My Contributions
I can't get my code to work for my radio buttons. does anyone have any suggestions on what to do? Thanks in advance.
CODE
<?php $errors = array(); if(isset($_POST["submit"])) { if($_POST["dealershipname"] == "") { $errors["dealershipname"] = "Please enter your dealership name"; } if($_POST["dealernumber"] == "") { $errors["dealernumber"] = "Please enter your dealer number"; } if($_POST["phonenumber"] == "") { $errors["phonenumber"] = "Please enter your phone number"; } if($_POST["yourname"] == "") { $errors["yourname"] = "Please enter your name"; } if($_POST["model"] == "" && $_POST["athenapro"] == "" && $_POST["athenachopper"] == "" && $_POST["sledpro"] == "" && $_POST["sledchopper"] == "" && $_POST["devilpro"] == "" && $_POST["devilchopper"] == "" && $_POST["venompro"] == "" && $_POST["venomchopper"] == "" && $_POST["mercrigid"] == "" && $_POST["mercsoftail"] == "" && $_POST["reaperchopper"] == "" && $_POST["demonrigid"] == "" && $_POST["misspro"] == "") { $errors["model"] = "Please choose a model"; } // if($_POST["model"] == "") { //$errors["model"] = "Please choose the model you would like"; // } //if($_POST["wheels"] == "") { //$errors["wheels"] = "Please choose the type of wheel you would like"; //} // if($_POST["basecolor"] == "") { //$errors["basecolor"] = "Please choose a base color"; // } // if($_POST["graphics"] == "") { // $errors["graphics"] = "Please choose a graphic"; // } // if($_POST["graphicmaincolor"] == "") { // // $errors["graphicmaincolor"] = "Please choose a main color for your graphic"; // } // if($_POST["pinstripecolor"] == "") { // $errors["pinstripecolor"] = "Please choose a pin stripe color"; // } // if($_POST["graphicmaincolor"] == "") { // $errors["graphicmaincolor"] = "Please choose a main color for your graphic"; // } // if($_POST["pinstripecolor"] == "") { // $errors["pinstripecolor"] = "Please choose a pin stripe color"; // } if(count($errors) == 0) { header("Location: /dev/bbc/processorderform3.php?dealershipname=" . $_POST["dealershipname"] . "dealernumber=" . $_POST["dealernumber"] . "yourname=" . $_POST["yourname"] . "phonenumber=" . $_POST["phonenumber"] . "model=" . $_POST["model"] . "wheels=" . $_POST["wheels"] . "basecolor=" . $_POST["basecolor"] . "graphics=" . $_POST["graphics"] . "graphicmaincolor=" . $_POST["graphicmaincolor"] . "pinstripecolor=" . $_POST["pinstripecolor"] . "chrome=" . $_POST["chrome"] . "realflamecolor=" . $_POST["realflamecolor"] . "otherstuff=" . $_POST["otherstuff"] . "comments=" . $_POST["comments"]); exit; } } ?> <html> <?php //Obj_A DISPLAY ERRORS if(count($errors) > 0) { foreach($errors as $why => $value) { echo '<font color="red" face= "arial"><p>Error: <u><b>' . $errors[$why] . '</b></u></p></font>'; } } ?> <!--<body background="images/bbc_bg.gif">--> <form action="index3.php" method="post"> <table border="0" width="100%" align="center" cellpadding="2" cellspacing="2"> <font face="arial"> <table border="0" width="801 px" align="center"> <tr><td> <table border="0" align="center" width="800px"> <tr><td align="left"><img src="images/bbc_header.jpg"></td></tr> <tr><td align="center"> <font face="arial" size="5px">DEALER MOTORCYCLE ORDER FORM</font><font face = "arial" size="1px"> Revised 04/03/07</font></td></tr> <tr><td> <table border="0" width="800 px" > <tr><td><b>Dealership Name:</td> <td align="left"><input type="text" name ="dealershipname" value="<? echo $_POST["dealershipname"] ?>" rows="1" cols="40"/></td> <td><b>Dealer Number:</td> <td><input type="text"name ="dealernumber" value="<? echo $_POST["dealernumber"] ?>" rows="1" cols="40"/></td></tr> <tr> <td><b>Phone Number:</td> <td align="left"><input type="text" name ="phonenumber" value="<? echo $_POST["phonenumber"] ?>" rows="1" cols="40"/></td> <td><b>Your Name:</td> </td><td><input type="text"name ="yourname" value="<? echo $_POST["yourname"] ?>" rows="1" cols="40"/></td> </tr> </table> <table border="0" > <tr><td><img src="images/bbc_1.gif"> <b>Models:</b></td></tr> <tr><td align = "center" colspan="8"><img src="images/bbc_bar.gif"></td></tr> <tr><td> <img src="images/models/athena.jpg"><br /><input type="radio" name="model" value="<? echo $_POST["athenapro"] ?>"/>ProStreet<br /> <input type="radio" name="model" value="<? echo $_POST["athenachopper"] ?>"/>Chopper </td> <td> <img src="images/models/thesled.jpg"><br /><input type="radio" name="model" value="<? echo $_POST["sledpro"] ?>"/>ProStreet<br /> <input type="radio" name="model" value="sledchopper"/>Chopper </td> <td> <img src="images/models/devilsadvocate.jpg"><br /><input type="radio" name="model" value="<? echo $_POST["devilpro"] ?>"/>ProStreet<br /> <input type="radio" name="model" value="<? echo $_POST["devilchopper"] ?>"/>Chopper </td> <td> <img src="images/models/venom.jpg"><br /> <input type="radio" name="model" value="<? echo $_POST["venompro"] ?> "/>ProStreet<br /> <input type="radio" name="model" value="<? echo $_POST["venomchopper"] ?>"/>Chopper </td> <td> <img src="images/models/merc.jpg"><br /><input type="radio" name="model" value="<? echo $_POST["mercrigid"] ?>"/>Rigid<br /> <input type="radio" name="model" value="<? echo $_POST["mercsoftail"] ?>"/>Softail </td> <td> <img src="images/models/reaper.jpg"><br /><input type="radio" name="model" value="<? echo $_POST["reaperchopper"] ?>"/>Chopper<br /> </td> <td> <img src="images/models/screamindemon.jpg"><br /><input type="radio" name="model" value="<? echo $_POST["demonrigid"] ?>"/>Rigid<br /> </td> <td> <img src="images/models/missbehavin.jpg"><br /><input type="radio" name="model" value="<? echo $_POST["misspro"] ?> "/>ProStreet<br /> </td> </tr> <tr><td align = "center" colspan="8"><img src="images/bbc_bar.gif"></td></tr> </table> <table border="0"> <tr><td><img src="images/bbc_2.gif"> <b>Wheels: </b></td></tr> <tr><td align = "center" colspan="9"><img src="images/bbc_bar.gif"></td></tr> <tr> <td align="center"><img src="images/wheels/rudementary.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["rude"] ?>"/><font size="2"><br />Rude-mentary</font> </td> <td align="center"><img src="images/wheels/poundfoolish.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["pound"] ?>"/><font size="2"><br />Poundfoolish</font> </td> <td align="center"><img src="images/wheels/5thdimension.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["dimension"] ?>"/><font size="2"><br />5th Dimension</font> </td> <td align="center"><img src="images/wheels/feverpitch.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["fever"] ?>"/><font size="2"><br />Fever Pitch</font> </td> <td align="center"><img src="images/wheels/engage.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["engage"] ?>"/><font size="2"><br />Engage</font> </td> <td align="center"> <td align="center"><img src="images/wheels/devilscandy.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["candy"] ?>"/><font size="2"><br />Devil's Candy</font> </td> <td align="center"><img src="images/wheels/pab.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["pab"] ?>"/><font size="2"><br />PAB</font> </td> <td align="center"><img src="images/wheels/spike.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["spike"] ?>"/><font size="2"><br />Spike</font> </td> <!-- <td align="center"><img src="images/wheels/spade.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["spade"] ?>"/><font size="2"><br />Spade</font> </td> <td align="center"><img src="images/wheels/web.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["web"] ?>"/><font size="2"><br />Web</font>--> </td> <td align="center"><img src="images/wheels/spoke.jpg"><br /><input type="radio" name="wheels" value="<? echo $_POST["spoke"] ?>"/><font size="2"><br />Spoke</font> </td> </tr> <tr> <td colspan="5"> <input type="radio" name="chrome" value="<? echo $_POST["chromewheels"] ?>"/><font size="2">Chrome the BBC Stock Wheels (Polished Standard)</font> <input type="radio" name="chrome" value="<? echo $_POST["nochromewheels"] ?>"/><font size="2">No Chrome</font> </td> </tr> <tr><td align = "center" colspan="9"><img src="images/bbc_bar.gif"></td></tr> </table> <table border="0" width=""> <tr><td colspan="10"><img src="images/bbc_3.gif"> <b>Paint</b></td> <tr><td colspan="10"><img src="images/bbc_bar.gif"></td></tr> <td colspan="10"><b>Base Color: </b></td></tr> <tr><td align="center"> <img src="images/colors/glossblack.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["gblack"] ?>"/><br /><font size="2">Gloss<br /> Black</font> </td> <td align="center"> <img src="images/colors/stainblack.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["sblack"] ?>/><br /><font size="2">Stain<br /> Black</font> </td> <td align="center"> <img src="images/colors/silvermetallic.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["smetallic"] ?>"/><br /><font size="2">Silver<br /> Metallic</font> </td> <td align="center"> <img src="images/colors/charcoalmetallic.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["cmetallic"] ?>"/><br /><font size="2">Charcoal<br /> Metallic</font> </td> <td align="center"> <img src="images/colors/orangepearl.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["orange"] ?>"/><br /><font size="2">Orange<br /> Pearl</font> </td> <td align="center"> <img src="images/colors/electricblue.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["blue"] ?>"/><br /><font size="2">Electric<br /> Blue</font> </td> <td align="center"> <img src="images/colors/firecrackerred.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["fred"] ?>"/><br /><font size="2">Firecracker<br /> Red</font> </td> <td align="center"> <img src="images/colors/candyred.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["cred"] ?>"/><br /><font size="2">Candy<br /> Red</font> </td> <td align="center"> <img src="images/colors/blackcherry.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["cherry"] ?>"/><br /><font size="2">Black<br /> Cherry</font> </td> <td align="center"> <img src="images/colors/pearlwhite.jpg"><br /><input type="radio" name="basecolor" value="<? echo $_POST["white"] ?>"/><br /><font size="2">Pearl White</font><br /><font size="1">(Miss Behavin' Only)</font> </select> </td> </tr> <td colspan="3"><b>Graphics: </b> <select name="graphics"> <option value=graphicsdefault"></option> <option value="<? echo $_POST["flames"] ?>" >Paneled Flames</option> <option value="<? echo $_POST["rflames"] ?>" >Realistic Flames</option> <option value="<? echo $_POST["scallops"] ?>" >Scallops</option> <option value="<? echo $_POST["tribal"] ?>" >Tribal</option> <option value="<? echo $_POST["custom"] ?>" >Custom(call for quote)</option> </select> </td> </tr> </table> <table border="0" width="800px"> <tr><td><b>Graphic Colors:</b></td> <td><b>Main Color: </b><br /> <select name="graphicmaincolor"> <option value=graphicmaincolordefault"></option> <option value="<? echo $_POST["ggblack"] ?>" >Gloss Black</option> <option value="<? echo $_POST["gsblack"] ?>">Stain Black</option> <option value="<? echo $_POST["gsmetallic"] ?>" >Silver Metallic</option> <option value="<? echo $_POST["gcmetallic"] ?>" >Charcoal Metallic</option> <option value="<? echo $_POST["gorange"] ?>" >Orange Pearl</option> <option value="<? echo $_POST["gblue"] ?>" >Electric Blue</option> <option value="<? echo $_POST["gfred"] ?>" >Firecracker Red</option> <option value="<? echo $_POST["gcred"] ?>" >Candy Red</option> <option value="<? echo $_POST["gcherry"] ?>" >Black Cherry</option> <option value="<? echo $_POST["gwhite"] ?>" >Pearl White(Miss Behavin Only)</option> </select> </td> <td><b>Pinstripe Color: </b><br /> <select name="pinstripecolor"> <option value=pinstripecolordefault"></option> <option value="<? echo $_POST["pgblack"] ?>" >Gloss Black</option> <option value="<? echo $_POST["psblack"] ?>" >Silver Metallic</option> <option value="<? echo $_POST["pcmetallic"] ?>" >Charcoal Metallic</option> <option value="<? echo $_POST["porange"] ?>" >Orange Pearl</option> <option value="<? echo $_POST["pblue"] ?>" >Electric Blue</option> <option value="<? echo $_POST["pfred"] ?>" >Firecracker Red</option> <option value="<? echo $_POST["pcred"] ?>" >Candy Red</option> <option value="<? echo $_POST["pcherry"] ?>" >Black Cherry</option> <option value="<? echo $_POST["pwhite"] ?>" >Pearl White(Miss Behavin Only)</option> </select> </td> <td><b>Real Flame Color: </b><font size="1">(If Applicable)</font><br /> <select name="realflamecolor"> <option value=realflamecolordefault"></option> <option value="<? echo $_POST["fgblack"] ?>" >Gloss Black</option> <option value="<? echo $_POST["fsblack"] ?>" >Stain Black</option> <option value="<? echo $_POST["fsmetallic"] ?> >Silver Metallic</option> <option value="<? echo $_POST["fcmetallic"] ?> >Charcoal Metallic</option> <option value="<? echo $_POST["forange"] ?> >Orange Pearl</option> <option value="<? echo $_POST["fblue"] ?> >Electric Blue</option> <option value="<? echo $_POST["ffred"] ?> >Firecracker Red</option> <option value="<? echo $_POST["fcred"] ?> >Candy Red</option> <option value="<? echo $_POST["fcherry"] ?> >Black Cherry</option> <option value="<? echo $_POST["fwhite"] ?> >Pearl White(Miss Behavin Only)</option> </select> </td> </tr> <tr><td align = "center" colspan="4"><img src="images/bbc_bar.gif"></td></tr> </table> <table border="0" width="800px"> <tr><td><img src="images/bbc_4.gif"> <b>Other Stuff:</b> <input type="checkbox" name="otherstuff" value="<? echo $_POST["enclosed"] ?> />BBC Enclosed Primary Drive <input type="checkbox" name="otherstuff" value="<? echo $_POST["open"] ?> />BDL Open Primary Drive <input type="checkbox" name="otherstuff" value="<? echo $_POST["other"] ?> />Other <textarea name ="textother" value="<? echo $_POST["textother"] ?> /></textarea> </td> </tr> <tr><td align = "center" ><img src="images/bbc_bar.gif"></td></tr> </table> <table border="0"> <tr><td><img src="images/bbc_5.gif"> <b>Comments:</b></td></tr> <tr><td colspan="3"> <textarea name ="comments" value="<? echo $_POST["comments"] ?> cols="100%" rows="5" wrap="wrap"/></textarea> </td></tr> <tr><td> <td align="right"><input type="submit" name="submit" /></td> </td></tr> </tr> </table> </td></tr> <tr><td align="left"><img src="images/bbc_footer.jpg"></td></tr> </table> </td></tr> </table> </form> </body> </html>
[edit] use code tags next time please.
bphishin
19 Jun, 2007 - 02:54 PM
New D.I.C Head
Joined: 19 Jun, 2007
Posts: 5
My Contributions
QUOTE(skyhawk133 @ 19 Jun, 2007 - 12:31 PM)
Gonna need a little more info than that big guy. That's a lot of code to say "my radio buttons don't work" What don't they do that you want them to do? Are you getting errors? Help us out a little. Also, in the future, please put [code] tags around your code... just like the big image said to do.
I am having a hard time validating my radio buttons.... My radio buttons work, but the code I wrote to validate (make sure at least one was checked) is not working out.
Basically, I need to make sure that at least one radio button is checked for a model. Thanks for the response and i hope my reply helps.
bphishin
19 Jun, 2007 - 03:24 PM
New D.I.C Head
Joined: 19 Jun, 2007
Posts: 5
My Contributions
QUOTE(Styx @ 19 Jun, 2007 - 04:02 PM)
Well, there's a couple reasons why they don't work. First, you're setting a value on them based on a $_POST value when they should be constant so you know what you're talking about. Second, if you want them to be checked, as in one or the other is actually checked in, if the user has to stay on that page, then you need a switch to put in the tag, such as:
CODE
$check1 = (isset($_POST['check1'])) ? 'checked="checked"' : ''; $check2 = (isset($_POST['check2'])) ? 'checked="checked"' : '';
and $check1 and 2 would be put just before the closing of the radio input tag for each respectively.
The reason I am setting a value to each radio button is because once the form is filled out, I will be emailing the data from the form to my customer. So each radio button has it's own value. Should I create constants for each value of the radio button then?
Styx
19 Jun, 2007 - 11:53 PM
D.I.C Head
Joined: 4 Mar, 2007
Posts: 192
Dream Kudos: 225
My Contributions
Err, for my last post, I meant something like
CODE
<?php $check1 = ($_POST['radio'] == 1) ? 'checked="checked"' : ''; $check2 = ($_POST['radio'] == 0) ? 'checked="checked"' : ''; ?> <form method="post"> Yes <input type="radio" name="radio" value="1" <?php echo $check1; ?>> No <input type="radio" name="radio" value="0" <?php echo $check2; ?>> <input type="submit"> </form>
sorry x_x I was thinking about checkboxes for some reason
does that make sense now?
The check1 determines whether or not it is checked and whether or not that radio switch is set. If you do it your way, the values will always remain empty.
Then you could send over $_POST['radio'] or else use it to determine some other value (like if you had an array $options = array('No', 'Yes') you could do $options[$_POST['radio']])
bphishin
26 Jun, 2007 - 09:40 AM
New D.I.C Head
Joined: 19 Jun, 2007
Posts: 5
My Contributions
QUOTE(Styx @ 20 Jun, 2007 - 12:53 AM)
Err, for my last post, I meant something like
CODE
<?php $check1 = ($_POST['radio'] == 1) ? 'checked="checked"' : ''; $check2 = ($_POST['radio'] == 0) ? 'checked="checked"' : ''; ?> <form method="post"> Yes <input type="radio" name="radio" value="1" <?php echo $check1; ?>> No <input type="radio" name="radio" value="0" <?php echo $check2; ?>> <input type="submit"> </form>
sorry x_x I was thinking about checkboxes for some reason
does that make sense now?
The check1 determines whether or not it is checked and whether or not that radio switch is set. If you do it your way, the values will always remain empty.
Then you could send over $_POST['radio'] or else use it to determine some other value (like if you had an array $options = array('No', 'Yes') you could do $options[$_POST['radio']])
This is driving me CRAZY!!!! I still can't get it to work!!! ugh!!!!
any other tips to solve this problem?
Reference Sheets
Bye Bye Ads
Free DIC T-Shirt
Related Sites
Monthly Drawing
Partners
Top Contributors
Top 10 Kudos This Month