Link to home
Start Free TrialLog in
Avatar of atari2600
atari2600Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Remove unwanted variables from URL when using GET in an HTML form

Hi,

I have an HTML form which is self populating from a database. The form is a series of dropdowns. The form is used to choose parameters for a search/filter function, The problem I have is that all variables are sent to the URL even when empty. For example:

http://www.example.co.uk/scooters-list-test.php?model_range=Speedfight&engine_size=&stroke_type=&cooling_system=&colours=&promotion_id_use=&submit=GO!

When really I need the URL to be:

http://www.example.co.uk/scooters-list-test.php?model_range=Speedfight

How do I stop all these unwanted variables from being in the URL? There are a number of reasons why I want them removed.

Here is an example of the form I am using:

			<form method="get" action="scooters-list-test.php?"/>
            <select name = "model_range" > 
            	<option value = "">All Models</option>
				<?php foreach (getListOptions('products_scooters', 'model_range') as $value => $label): ?> 
				<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['model_range']);?>><?php echo $label; ?></option> 
				<?php endforeach ?> 
 			</select>
            <select name = "engine_size"> 
				<option value = "">All Engine Types</option>
				<?php foreach (getListOptions('products_scooters', 'engine_size') as $value => $label): ?> 
				<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['engine_size']);?>><?php echo $label; ?></option> 
				<?php endforeach ?> 
 			</select>
            <select name = "stroke_type"> 
				<option value = "">All Stroke types</option>
				<?php foreach (getListOptions('products_scooters', 'stroke_type') as $value => $label): ?> 
				<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['stroke_type']);?>><?php echo $label; ?></option> 
				<?php endforeach ?> 
 			</select>
            <select name = "cooling_system" > 
				<option value = "">All Cooling Options</option>
				<?php foreach (getListOptions('products_scooters', 'cooling_system') as $value => $label): ?> 
				<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['cooling_system']);?>><?php echo $label; ?></option> 
				<?php endforeach ?> 
 			</select>
            <select name = "colours" > 
				<option value = "">All Colour Options</option>
				<?php foreach (getListOptions('products_scooters', 'colours') as $value => $label): ?> 
				<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['colours']);?>><?php echo $label; ?></option> 
				<?php endforeach ?> 
 			</select>
            <select name = "promotion_id_use" > 
				<option value = "">With / Without Promotion</option>
				<?php foreach (getListOptions('products_scooters', 'promotion_id_use') as $value => $label): ?> 
				<option value = "<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['promotion_id_use']);?>><?php echo $label; ?></option> 
				<?php endforeach ?> 
 			</select>   
            
           <input type="submit" name="submit" value="GO!" />

Open in new window


Avatar of h4hardy
h4hardy
Flag of United States of America image

just  replace the below line of code ..and it's work..
<form method="post" action="scooters-list-test.php?"/>

Open in new window


let me know your view.

     
Avatar of atari2600

ASKER

Hi h4hardy,

Thanks, but I need the relevant variables to show. Otherwise bookmarking a search result will not be practical.
no issue.. you can use the $_POST.. try the below code at your page where the form has been taken away after submitting the things..

in your case your action page is "scooters-list-test.php" so at there just type the below code..


<?php

echo "<pre>";
print_r($_POST);

?>

Open in new window


Note : don't forget to select any value from the  HTML page where the drop down is listed



ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Great solution! Exactly what I was looking for.
Out of curiosity how would I remove the:
&submit=GO!
at the end of the URL?
Actually just worked out how to do that :) Thanks again....
>Out of curiosity how would I remove the:
>&submit=GO!

Add this line : document.getElementsByName("submit')[0].disabled = true;

It's a bad practice to give a field the name "submit"
Change it to Submit or mysubmit