PYRRHIC Posted April 27, 2011 Share Posted April 27, 2011 I have been searching for something like this to use so I am trying to implement these ideas for my form but unable to get it to work. The concept is similar so I am posting here but if I would make a new post just let me know. it is not posting the info when the radio button is checked. Someone with a keener eye that mine can give a look and tell what I have done incorrectly it would be appreciated. echo ' <form action="" method="get"><div id="avatar_section"> <div id="avatar_stack"> <p> <img src="herotmb/face0.png" alt="" /><input name="avatar[head]" type="radio" value="face0" checked="checked" /> </p> <p> <img src="herotmb/face0.png" alt="" /><input type="radio" name="avatar[face]" value="face0" /> <img src="herotmb/face1.png" alt="" /><input type="radio" name="avatar[face]" value="face1" /> <img src="herotmb/face2.png" alt="" /><input type="radio" name="avatar[face]" value="face2" /> <img src="herotmb/face3.png" alt="" /><input type="radio" name="avatar[face]" value="face3" /> </p> <span name="color"> <p> <img src="herotmb/color0.png" alt="" /><input type="radio" name="avatar[color]" value="black" id="black" onclick="color(black);" /> <img src="herotmb/color1.png" alt="" /><input type="radio" name="avatar[color]" value="brown" id="brown" /> <img src="herotmb/color2.png" alt="" /><input type="radio" name="avatar[color]" value="darkbrown" id="darkbrown" onclick="color(darkbrown);" /> <img src="herotmb/color3.png" alt="" /><input type="radio" name="avatar[color]" value="yellow" id="red" onclick="color(red);" /> <img src="herotmb/color4.png" alt="" /><input type="radio" name="avatar[color]" value="red" id="yellow" onclick="color(yellow);" /> </p> </span> '; $selected_radio = '$_POST[avatar[color]]'; if ($selected_radio == 'black') { echo ' <p> <img src="herotmb/hair0-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair0-black" /> <img src="herotmb/hair1-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair1-black" /> <img src="herotmb/hair2-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair2-black" /> <img src="herotmb/hair3-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair3-black" /> <img src="herotmb/hair4-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair4-black" /> <img src="herotmb/hair5-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair5-black" /> <img src="herotmb/hair6-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hair6-black" /> <img src="herotmb/hairNone-black.png" alt="" /><input name="avatar[hair]" type="radio" value="hairNone" /> </p>'; } else if ($selected_radio == 'brown') { echo 'Table 2 Here.'; } else if ($selected_radio == 'darkbrown') { echo 'Table 3 Here.'; } else if ($selected_radio == 'red') { echo 'Table 4 Here.'; } else if ($selected_radio == 'yellow') { echo 'Table 5 Here.'; } echo ' <p id="submit" > <input type="submit" value="Save" /> </p> </form>'; Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/ Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 (Post split to its own thread) Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1206944 Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 do you receive any errors from this script? Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1206946 Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 The variable in this line is being interpreted as a string literal because it is in single quotes, also the square brackets are misplaced and the indices should be quoted. $selected_radio = '$_POST[avatar[color]]'; It should read; $selected_radio = $_POST['avatar']['color']; Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1206947 Share on other sites More sharing options...
PYRRHIC Posted April 28, 2011 Author Share Posted April 28, 2011 wow, didn't know this was moved thought it got deleted and almost posted it again. good thing I was searching and thanks for just moving it Thanks for the replies, no I am not getting an error messages the tab info is just not showing. I tried $selected_radio = $_POST['avatar']['color']; but the tab info is now being skip. what I mean by that is the info from 2 tabs down is showing in its place. any other suggestions. I can post the JS info which is making the tabs if need be. thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207336 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 You can view all your posts from your profile. too. Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207365 Share on other sites More sharing options...
PYRRHIC Posted April 28, 2011 Author Share Posted April 28, 2011 I will keep that in mind, thanks I added error_reporting and now I am getting an error line 113 112 $selected_radio = $_POST["avatar[color]"]; 113 if ($selected_radio == "black") { 114 echo ' when I change == to != the info shows up but does not switch to (Table 2 here) so I am assuming, and correct me if Im wrong, that the value from selected_radio is not being recognized. how would I fix this ? Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207398 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 $selected_radio = $_POST["avatar[color]"]; // <--- is wrong (still) $_POST['avatar']['color'] // <--- Should be The root problem here is that your form method is get, but you're attempting to access variables in the $_POST array. Either change the form method to post, or access the data using the $_GET array. Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207620 Share on other sites More sharing options...
PYRRHIC Posted April 28, 2011 Author Share Posted April 28, 2011 ok thanks for your input. Since Im getting "Undefined index: avatar", even in array the problem still wouldn't be solved, would it I've even removed the extra brackets, now its avatar_color. would I be trying to make the array for both the avatar_color and avatar_hair or just one of the sections? Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207657 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207676 Share on other sites More sharing options...
PYRRHIC Posted April 28, 2011 Author Share Posted April 28, 2011 tried changing method to post and using $_GET[avatar_color] way no luck <form action="" method="post"><div id="avatar_section"> <div id="avatar_stack"> <p> <img src="herotmb/face0.png" alt="" /><input name="avatar_head" type="radio" value="face0" checked="checked" /> </p> <p> <img src="herotmb/face.png" alt="" /><input type="radio" name="avatar_face" value="face0" /> <img src="herotmb/face1.png" alt="" /><input name="avatar_face" type="radio" value="face1" /> <img src="herotmb/face2.png" alt="" /><input name="avatar_face" type="radio" value="face2" /> <img src="herotmb/face3.png" alt="" /><input name="avatar_face" type="radio" value="face3" /> </p> <p> <img src="herotmb/color0.png" alt="" /><input type="radio" name="avatar_color" value="black" id="black" /> <img src="herotmb/color1.png" alt="" /><input type="radio" name="avatar_color" value="brown" id="brown" onclick="color(brown);" /> <img src="herotmb/color2.png" alt="" /><input type="radio" name="avatar_color" value="darkbrown" id="darkbrown" onclick="color(darkbrown);" /> <img src="herotmb/color3.png" alt="" /><input type="radio" name="avatar_color" value="yellow" id="red" onclick="color(red);" /> <img src="herotmb/color4.png" alt="" /><input type="radio" name="avatar_color" value="red" id="yellow" onclick="color(yellow);" /> </p> <?php $selected_radio = $_GET['avatar_color']; ---line102----- if ($selected_radio == 'black') { echo ' <p> <img src="herotmb/hair0-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair0-black" /> <img src="herotmb/hair1-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair1-black" /> <img src="herotmb/hair2-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair2-black" /> <img src="herotmb/hair3-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair3-black" /> <img src="herotmb/hair4-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair4-black" /> <img src="herotmb/hair5-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair5-black" /> <img src="herotmb/hair6-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair6-black" /> <img src="herotmb/hairNone-black.png" alt="" /><input name="avatar_hair" type="radio" value="hairNone" /> </p>'; } else if ($selected_radio == 'brown') { echo ' <p> <img src="herotmb/hair0-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair0-brown" /> <img src="herotmb/hair1-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair1-brown" /> <img src="herotmb/hair2-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair2-brown" /> <img src="herotmb/hair3-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair3-brown" /> <img src="herotmb/hair4-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair4-brown" /> <img src="herotmb/hair4-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair4-brown" /> <img src="herotmb/hairNone-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hairNone" /> </p>'; } else if ($selected_radio == 'darkbrown') { echo 'Table 3 Here.'; } Notice: Undefined index: avatar_color in index20.php on line 102 (yes this is attempt 20) Trying to make an array as you suggested, how does this look $array = array('color'=> 'black','brown','darkbrown','red','yellow'); echo ' <p> <img src="herotmb/$array.png" alt="" /><input type="radio" name="avatar_color" value="$array" id="$array" />'; </p>'; Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207691 Share on other sites More sharing options...
Pikachu2000 Posted April 28, 2011 Share Posted April 28, 2011 The data from a form will be available in the superglobal array that matches the form's method. I.E. a for with the method set to post will pass the data in the $_POST array. A form with the method set to get will send data inthe $_GET array (and the data should be visible in the URL string). You're getting an undefined index error because you don't check to see if the index is present in the array (which it won't be, because of the $_POST/$_GET mismatch) before attempting to access it. <?php if( !empty($_POST['avatar_color']) ) { $selected_radio = $_POST['avatar_color']; if ($selected_radio == 'black') { echo ' <p> <img src="herotmb/hair0-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair0-black" /> <img src="herotmb/hair1-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair1-black" /> <img src="herotmb/hair2-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair2-black" /> <img src="herotmb/hair3-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair3-black" /> <img src="herotmb/hair4-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair4-black" /> <img src="herotmb/hair5-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair5-black" /> <img src="herotmb/hair6-black.png" alt="" /><input name="avatar_hair" type="radio" value="hair6-black" /> <img src="herotmb/hairNone-black.png" alt="" /><input name="avatar_hair" type="radio" value="hairNone" /> </p>'; } else if ($selected_radio == 'brown') { echo ' <p> <img src="herotmb/hair0-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair0-brown" /> <img src="herotmb/hair1-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair1-brown" /> <img src="herotmb/hair2-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair2-brown" /> <img src="herotmb/hair3-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair3-brown" /> <img src="herotmb/hair4-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair4-brown" /> <img src="herotmb/hair4-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hair4-brown" /> <img src="herotmb/hairNone-brown.png" alt="" /><input name="avatar_hair" type="radio" value="hairNone" /> </p>'; } else if ($selected_radio == 'darkbrown') { echo 'Table 3 Here.'; } } Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1207700 Share on other sites More sharing options...
PYRRHIC Posted April 29, 2011 Author Share Posted April 29, 2011 thanks for your reply. although the undefined message is no longer appearing the result has not change, doesnt seem recognize the the radio names avatar_color. Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1208021 Share on other sites More sharing options...
Pikachu2000 Posted April 29, 2011 Share Posted April 29, 2011 Post your code in its current form . . . Quote Link to comment https://forums.phpfreaks.com/topic/234867-radio-buttons-html-and-php/#findComment-1208401 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.