Jump to content

Multiple forms but keep URL Parameter


petenaylor

Recommended Posts

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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()">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.