Darkmatter5 Posted January 5, 2009 Share Posted January 5, 2009 Okay I have two droplists "system" and "genre" and a submit button. 1. How can I create code that would execute when the button is pressed? 2. How can I take the values of "system" and "genre" and put them into a string variable that have the pages current URL, but appends the values to the end and then reloads the page with those variables passed in the URL? Example: Current URL "http://www.something.com/page.php" System value "1" Genre value "1" Reload the page with "http://www.something.com/page.php?system=1&genre=1" Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/ Share on other sites More sharing options...
KevinM1 Posted January 5, 2009 Share Posted January 5, 2009 Okay I have two droplists "system" and "genre" and a submit button. 1. How can I create code that would execute when the button is pressed? 2. How can I take the values of "system" and "genre" and put them into a string variable that have the pages current URL, but appends the values to the end and then reloads the page with those variables passed in the URL? Example: Current URL "http://www.something.com/page.php" System value "1" Genre value "1" Reload the page with "http://www.something.com/page.php?system=1&genre=1" Thanks! Hmm...Almost sounds like homework. Have you tried something like: <?php if(isset($_GET['submit'])) { if(isset($_GET['system']) && isset($_GET['genre'])) { /* load the content specific for that system and genre */ } else { /* error? */ } } /*if the info HASN'T been submitted yet */ ?> <html> <head> <title>Blah</title> </head> <body> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="get"> <select name="system"> <!-- all of the 'system' options go here --> </select> <select name="genre"> <!-- all of the 'genre' options go here --> </select> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/#findComment-729979 Share on other sites More sharing options...
sniperscope Posted January 5, 2009 Share Posted January 5, 2009 how you ever tried <body> <form id="form1" name="form1" method="link" action="somepage.php?"> <table> <tr> <td><select name="system"> <option value="system_option_1">system_option_1</option> <option value="system_option_2">system_option_2</option> </select> </td> <td><select name="genre"> <option value="genre_option_1">genre_option_1</option> <option value="genre_option_2">genre_option_2</option> </select> </td> </tr> <tr> <td> </td> <td><input type="submit" value="Submit" /></td> </tr> </table> </form> </body> Quote Link to comment https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/#findComment-730012 Share on other sites More sharing options...
Darkmatter5 Posted January 5, 2009 Author Share Posted January 5, 2009 Perfect ideas. I went with the first one and here's what I got. <form method="get" name="vgames" action="<?php $_SERVER['PHP_SELF'] ?>"> <table align="left" cellpadding="0" cellspacing="0" border="0"> <tr> <td bgcolor="#993366"> <?php $vein->list_systems(1,$_GET['systems']); echo " "; $vein->list_genres(2,$_GET['genres']); ?> <input name='search' type='submit' class='button' tabindex='3' value='Search now'/><br> <?php $vein->list_numalpha_games($_GET['systems']); ?> </td> </tr> </table> </form> Now here's the URL it produces "http://www.something.com/site/vgames.php?systems=6&genres=4&search=Search+now". How can I get it to ignore search, which is the button? Quote Link to comment https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/#findComment-730126 Share on other sites More sharing options...
Maq Posted January 5, 2009 Share Posted January 5, 2009 Just don't add $_GET['search'] to the URL? Quote Link to comment https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/#findComment-730133 Share on other sites More sharing options...
Darkmatter5 Posted January 5, 2009 Author Share Posted January 5, 2009 But by using the mentioned method it's automatically taking all values from all form items within the form tags and applying them to the action which is reloading the page. how can I get it to ignore search? Quote Link to comment https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/#findComment-730156 Share on other sites More sharing options...
sniperscope Posted January 6, 2009 Share Posted January 6, 2009 But by using the mentioned method it's automatically taking all values from all form items within the form tags and applying them to the action which is reloading the page. how can I get it to ignore search? you can simply remove name attribute from form element. i.e. <input type="text" value="Some_Value"> Quote Link to comment https://forums.phpfreaks.com/topic/139549-passing-variables-to-url/#findComment-730633 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.