giraffemedia Posted July 15, 2008 Share Posted July 15, 2008 Hi is it possible to send a variable to a URL from a form list by using the action? What I want to do is select a value from a menu/list and print that as a variable in the URL on the resulting page. Here is some test code... <? $issue = $_POST['search']; ?> <form action="/test/search.php?search_by=<? echo $issue; ?>" method="post"> <select name="search" id="search"> <option value="">No.</option> <option value="">---</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> <input type="submit" name="button" id="tools_button" value="Go" /> </form> ?> Is this close or is there a different way to achieve this? Thanks for looking. James Link to comment https://forums.phpfreaks.com/topic/114856-solved-pass-variable-to-url-from-form-list/ Share on other sites More sharing options...
JD* Posted July 15, 2008 Share Posted July 15, 2008 You need a script to process the form first. Try this: <? if(isset($_POST['button']) && $_POST['button'] == "Go") { header("Location:/test/search.php?search_by=".$_POST['search']; } else { ?> <form action="" method="post"> <select name="search" id="search"> <option value="">No.</option> <option value="">---</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> <input type="submit" name="button" id="tools_button" value="Go" /> </form> <? } ?> Link to comment https://forums.phpfreaks.com/topic/114856-solved-pass-variable-to-url-from-form-list/#findComment-590628 Share on other sites More sharing options...
giraffemedia Posted July 16, 2008 Author Share Posted July 16, 2008 Of course! That works a treat - although you left the closing bracket off in the header: line which took me a couple minutes to debug as I was getting a blank page! Thanks for you help JD. James Link to comment https://forums.phpfreaks.com/topic/114856-solved-pass-variable-to-url-from-form-list/#findComment-591343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.