Boxerman Posted February 8, 2010 Share Posted February 8, 2010 Hi guys, Im trying to get it so when a user selects something from the list it will update the URL and post the route.. heres my code <p>Preferred routes:</p> <form method="get" action="?"> <p>MTPP ARRIVALS</p> <p><select size="1" name=""> <option>MTCH-MTPP</option> <option>KJFK-MTPP</option> <option>KMIA-MTPP</option> <option>KFLL-MTPP</option> <option>TFFR-MTPP</option> <option>CYUL-MTPP</option> <option>TNCM-MTPP</option> <option>KBOS-MTPP</option> <option>CYYC-MTPP</option> <option>TNCC-MTPP</option> </select><input type="submit" value="Generate Route" name=""></p> <p><?php if (isset($_REQUEST['MTCH-MTPP'])){ echo "HCN G444 NOKEN PAP"; } ?> so it will be like index.php?MTCH-MTPP POSTS ROUTE HERE thanks Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/ Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 so you mean you would just need <form method="get" action="index.php"> That would give you the url that you want Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008817 Share on other sites More sharing options...
Boxerman Posted February 8, 2010 Author Share Posted February 8, 2010 Hi, theres a problem everytime i click it, it goes to this index.php?=MTCH-MTPP which is almost right.. i cant figure out where the = is coming from :S if that wasnt there it would work! Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008820 Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 ok the reason for this your unamed select should be <select name="route"> then you would get index.php?route=MTCH-MTPP which you should be able to work with Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008821 Share on other sites More sharing options...
Boxerman Posted February 8, 2010 Author Share Posted February 8, 2010 ok i changed it and when i go the url is index.php?route=MTCH-MTPP but on my php the REQUEST is only if (isset($_REQUEST['MTCH-MTPP'])){ what else could be causing no show? Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008827 Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 if you absolutely need to just have index.php?MTCH-MTPP, then you would need to do this <script type="text/javascript"> function setRoute() { var elem = document.getElementById('route'); var route = elem.options[elem.selectedIndex].value; document.location.href = 'index.php?'+route; } </script> <select name="route" id="route"> .... </select> <input type="button" onclick="setRoute()" value="Generate Route" /> Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008828 Share on other sites More sharing options...
alexjb Posted February 8, 2010 Share Posted February 8, 2010 If your url is index.php?route=MTCH-MTPP to retrieve the route, you would just use: $_REQUEST['route'] Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008830 Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 you have no $_REQUEST['MTCH-MTPP'] what you would have is $_REQUEST['route'] and that will be equal to the route selected so if($_REQUEST['route'] == 'MTCH-HTPP') { do something Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008831 Share on other sites More sharing options...
Boxerman Posted February 8, 2010 Author Share Posted February 8, 2010 JL5501 THANKS YOU SIR!!! Link to comment https://forums.phpfreaks.com/topic/191343-problem-with-getting-data-from-form/#findComment-1008834 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.