petenaylor Posted September 13, 2011 Share Posted September 13, 2011 Hi all I have a form that i need to submit a get to the URL and then a second form that sends a different URL parameter but keeps the first in place? Here's my code: <select name="category" onChange="this.form.submit();"> <option value= >--Choose category--</option> <?php $getcats = mysql_query (" SELECT * FROM `categories` ORDER by name ASC"); while ($showcats = mysql_fetch_array($getcats)) { echo "<option value=\"".$showcats['id']."\"".(($_GET['category']==$showcats['id']) ? ' selected="selected"':'').">".$showcats['name']."</option>"; } ?> </select> </form> <form id="make" name="make" method="GET" action="create-advert.php?category='<?php echo $_GET['category']; ?>"> <select name="make" onchange="this.form.submit();"> <option>--Choose make--</option> <?php $getmakes = mysql_query (" SELECT * FROM `makes` ORDER by name ASC"); while ($showmakes = mysql_fetch_array($getmakes)) { echo "<option value=\"".$showmakes['id']."\"".(($_SESSION['make']==$showmakes['id']) ? ' selected="selected"':'').">".$showmakes['name']."</option>"; } ?> </select> </form> Each time I select the make in the second form the url parameter 'category' disappears from the first? Many thanks Pete [/code] Quote Link to comment https://forums.phpfreaks.com/topic/247073-multiple-forms-but-keep-url-parameter/ Share on other sites More sharing options...
voip03 Posted September 13, 2011 Share Posted September 13, 2011 Can you give me more details about what you are trying to do? output will help . Quote Link to comment https://forums.phpfreaks.com/topic/247073-multiple-forms-but-keep-url-parameter/#findComment-1268892 Share on other sites More sharing options...
petenaylor Posted September 13, 2011 Author Share Posted September 13, 2011 Hi there My page basically consists of a number of fields that a user fills in to place an advert. Firstly they select a category and then depending on which category they selected, a drop down will appear for a make of caravan. They then select the make to reveal the models for that make. Each parameter determines the options to the users. I need the first drop down to send the category parameter to the URL and the next drop down to send the make to the url. So it looks like create-advert.php?category=1&make=22 for example. Thanks Pete Quote Link to comment https://forums.phpfreaks.com/topic/247073-multiple-forms-but-keep-url-parameter/#findComment-1268898 Share on other sites More sharing options...
xyph Posted September 13, 2011 Share Posted September 13, 2011 You shouldn't use GET as the form method. It will over-ride any other data you have in your query string. See this example <?php print_r( $_GET ); echo '<br>'; print_r( $_POST ); ?> <form method="get" action="temp.php?something=blah"><input type="text" name="lol"><input type="submit" value="Submit GET"></form> <br> <form method="post" action="temp.php?something=blah"><input type="text" name="lol"><input type="submit" value="Submit POST"></form> If you really want the values in the query string, use a solution like this <?php print_r( $_GET ); ?> <script type="text/javascript"> function doForm() { location.href = 'temp.php?something=blah&textinput=' + document.getElementById('text').value; } </script><br> <input type="text" name="textinput" id="text"> <input type="button" value="Submit GET" onclick="doForm()"> Quote Link to comment https://forums.phpfreaks.com/topic/247073-multiple-forms-but-keep-url-parameter/#findComment-1268900 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.