afallingpanda Posted December 5, 2013 Share Posted December 5, 2013 hello guys, ive made a script to basically execute two different things depending on which radio button is selected: print"<div style=\"position:absolute;bottom:20px;right:20px;\">"; print"<form method=\"post\" action=\"\">"; print"<input type=\"radio\" name=\"lang\" value=\"English\" >English<br>"; print"<input type=\"radio\" name=\"lang\" value=\"German\">German"; print"<input type=\"submit\" value=\"Change\" />"; print"</form>"; print"</div>"; $myRadio = intval($_POST['lang']); if ($myRadio == "English") { print"<h1>English</h1>"; }elseif ($myRadio == "German") { print"<h1>German</h1>"; } this doesnt work, firstly for some reason it just displays English straight away even though nothing is even ticked yet. and when i do change to "german" and click the button, it doesnt change... PLEASE help me guys, how would i make it work. Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/ Share on other sites More sharing options...
Ch0cu3r Posted December 5, 2013 Share Posted December 5, 2013 Remove intval(). This converts a value into integer. The if/elseif is comparing strings not integers. it just displays English straight away even though nothing is even ticked yet The comparison should only be performed if $_POST['lang'] exists. if(isset($_POST['lang'])) { $myRadio = $_POST['lang']; if ($myRadio == "English") { print"<h1>English</h1>"; } elseif ($myRadio == "German") { print"<h1>German</h1>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461358 Share on other sites More sharing options...
afallingpanda Posted December 5, 2013 Author Share Posted December 5, 2013 Remove intval(). This converts a value into integer. The if/elseif is comparing strings not integers. The comparison should only be performed if $_POST['lang'] exists. if(isset($_POST['lang'])) { $myRadio = $_POST['lang']; if ($myRadio == "English") { print"<h1>English</h1>"; } elseif ($myRadio == "German") { print"<h1>German</h1>"; } } ive done what you said, and the "english" isnt appearing there at the start but now when i tick a box and click submit, nothing appears Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461361 Share on other sites More sharing options...
Ch0cu3r Posted December 5, 2013 Share Posted December 5, 2013 ive done what you said, and the "english" isnt appearing there at the start but now when i tick a box and click submit, nothing appears It Displays the correct language based on the selection I make, and nothing if I didn't chose a language. Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461362 Share on other sites More sharing options...
afallingpanda Posted December 5, 2013 Author Share Posted December 5, 2013 It Displays the correct language based on the selection I make, and nothing if I didn't chose a language. print"<div style=\"position:absolute;bottom:20px;right:20px;\">"; print"<form method=\"post\" action=\"\">"; print"<input type=\"radio\" name=\"lang\" value=\"English\">English<br>"; print"<input type=\"radio\" name=\"lang\" value=\"German\">German"; print"<input type=\"submit\" value=\"Change\" />"; print"</form>"; print"</div>"; if(isset($_POST['lang'])) { $myRadio = $_POST['lang']; if ($myRadio == "English") { print"<h1>English</h1>"; } elseif ($myRadio == "German") { print"<h1>German</h1>"; } } theres my code.. and heres what i am seeing: http://gyazo.com/d19dd3d405d367365c86ba19240b1713 as you can see the h1 is not appearing Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461363 Share on other sites More sharing options...
Ch0cu3r Posted December 5, 2013 Share Posted December 5, 2013 (edited) What is the output of printf('<pre>%s</pre>', print_r($_POST, true)); When selecting a language and then submitting the form? Edited December 5, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461367 Share on other sites More sharing options...
afallingpanda Posted December 5, 2013 Author Share Posted December 5, 2013 What is the output of printf('<pre>%s</pre>', print_r($_POST, true)); When selecting a language and then submitting the form? sorry? where did you get this from?? printf('<pre>%s</pre>', print_r($_POST, true)); Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461370 Share on other sites More sharing options...
Ch0cu3r Posted December 5, 2013 Share Posted December 5, 2013 It is code I gave you so I can see the what is in $_POST when the form is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461371 Share on other sites More sharing options...
afallingpanda Posted December 5, 2013 Author Share Posted December 5, 2013 http://gyazo.com/24428ad07e1c606bb904c0658ae5b4b4 That is what the output is ( at the top its outputted). And by the way that is outputed as soon as the page loads, then when i choose and click submit it stays the same. THANKS SO FAR Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461372 Share on other sites More sharing options...
Ch0cu3r Posted December 5, 2013 Share Posted December 5, 2013 And that is with selecting English or German before clicking the button? If so then for some reason when the form is submitted the post data is not being sent. So is there more code to this? Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461373 Share on other sites More sharing options...
afallingpanda Posted December 5, 2013 Author Share Posted December 5, 2013 (edited) That is without selecting ANyTHING or clicking anything, it simply does that when i load the page. and thats all the code for this. i will now paste the code for that entire page: <?php $safe_myuri = addslashes($myuri); $row_parent_folder_title = $row_object_title; $row_parent_url = $row_url; $myquery = sql_query("SELECT * FROM webmanage_objects AS a WHERE a.parentid='$row_objectid' AND a.is_visible='1' AND a.archived='0' AND a.url='$safe_myuri' LIMIT 0,1"); if (!sql_num_rows($myquery)) { require("source/404error.php"); exit(); } else { $myrow = sql_fetch_assoc($myquery); transfer_row($myrow); } // // Machines for sale view // print_header($row_object_title); print "<div class=\"heading\"><div class=\"b\"><h2><a href=\"/machines-for-sale/\" style=\"text-decoration: none; color: #1e2a5f;\">Machines for Sale</a> > <a href=\"/machines-for-sale/$row_parent_url/\" style=\"text-decoration: none; color: #1e2a5f;\">$row_parent_folder_title</a></h2></div></div>\n"; print "<div class=\"clear\"></div>\n"; start_parkes_rounded(); print "<div class=\"hotspot blue tlc machine\">\n"; print "<div class=\"item\">\n"; print "<h2>$row_object_title</h2>\n"; print "<p class=\"red fRight cRight\"><strong>Stock Ref: $row_object_tagline</strong></p>\n"; print "<div class=\"clear\"></div>\n"; print "<div class=\"images\"> <script type=\"text/javascript\"> //<![CDATA[ Sys.WebForms.PageRequestManager._initialize('ctl00$Content$Scr1', document.getElementById('aspnetForm')); Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl00$Content$ImagesUP'], [], [], 90); //]]> </script>\n"; // // Images Container // $images = array(); $myquery = sql_query("SELECT * FROM webmanage_uploads WHERE filestore='image' AND objectid='$row_objectid' ORDER BY ordering, fileid"); while ($myrow = sql_fetch_assoc($myquery)) { $row_fileid = $myrow["fileid"]; if (is_file("$imagebase_location/$row_fileid"."_machine_large.jpg")) { $images[] = "/images/managed/$row_fileid"."_machine_large.jpg"; } } print "<div id=\"ctl00_Content_ImagesUP\">\n"; if (count($images)) { $myimage = $images[0]; print "<div class=\"main_image\">\n"; print " <img id=\"ctl00_Content_MainImage\" class=\"mainImage\" src=\"$myimage\" alt=\"$row_object_title\" style=\"border-width:0px;\" />\n"; print "</div>\n"; } print "<ul>\n"; $counter = 0; foreach($images as $myimage) { $counter++; if ($counter < 10) { $counter_text = "0$counter"; } else { $counter_text = "".$counter; } $myimage_small = str_replace("machine_large","machine_small",$myimage); if (($counter % 3) == 0) { $padding_right = "padding-right: 0px;"; } else { $padding_right = "padding-right: 15px;"; } print "<li id=\"ctl00_Content_RepMachineImages_ctl{$counter_text}_ImageItem\" style=\"$padding_right\"><a class=\"imagesListImage\" href='$myimage' target=\"_blank\" style=\"margin: 0px; float: left;\"><img id=\"ctl00_Content_RepMachineImages_ctl{$counter_text}_ListImage\" src=\"$myimage\" height=75 style=\"border-width: 0px; margin-left: auto; margin-right: auto;\" /></a></li>\n"; } print "</ul>\n"; print "</div>\n"; print "</div>\n"; print"<div style=\"position:absolute;bottom:20px;right:20px;\">"; print"<form method=\"post\" action=\"\">"; print"<input type=\"radio\" name=\"lang\" value=\"English\">English<br>"; print"<input type=\"radio\" name=\"lang\" value=\"German\">German"; print"<input type=\"submit\" value=\"Change\" />"; print"</form>"; print"</div>"; if(isset($_POST['lang'])) { $myRadio = $_POST['lang']; if ($myRadio == "English") { print"<h1>English</h1>"; } elseif ($myRadio == "German") { print"<h1>German</h1>"; } } printf('<pre>%s</pre>', print_r($_POST, true)); print "<div class=\"machine_details_right\"><div class=\"desc\">\n"; print "$row_object_content\n"; print "</div>\n"; print "<p class=\"buttons\">\n"; $safe_object_title = urlencode($row_object_title); print " <a id=\"ctl00_Content_EnquireBtn\" class=\"btn red-whi\" href=\"/index.php?page=contact&stock_ref=$row_object_tagline&desc=$safe_object_title\">Enquire about this machine</a>\n"; print " <a id=\"ctl00_Content_HlBackToListings\" class=\"btn grey\" href=\"./\">Back to listings</a>\n"; print "</p>\n"; print "<div class=\"clear\"></div>\n"; print "</div> <div class=\"clear\"></div> </div> <div class=\"clear\"></div> </div> <div class=\"clear\"></div>\n"; end_parkes_rounded(); print_footer(); ?> Edited December 5, 2013 by afallingpanda Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461374 Share on other sites More sharing options...
afallingpanda Posted December 6, 2013 Author Share Posted December 6, 2013 any help please Quote Link to comment https://forums.phpfreaks.com/topic/284555-please-help-with-radio-buttons/#findComment-1461465 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.