Long Url from Search Form

4 posts by 3 authors in: Forums > CMS Builder
Last Post: December 10, 2010   (RSS)

By rentittoday - May 17, 2010

Hello,

We are having an issue with our urls when you search. The URL Search query is displaying all of the fields in the search, even if they are not filled out. See below:
"http://www.rentittoday.com/viewers/apartment_for_rent_results.php?num_match=&subcategory_match=&bedrooms_min=&bedrooms_max=&rental_price_min=&rental_price_max=&city_keyword=&surrounding_area_keyword=&state_keyword=&zip_match=&submit=Search"/

I know we can change the form action from "get" to "post" to not display the query string but we do want it to show the part of the query that the user filled out. So for example, if a user was searching Florida, it would say "......php?state_keyword=FL"
We are pretty sure that this was the case but they all of a sudden we started having these strings that go on forever!

How can we get back to our old prettier strings?

Thanks,
Lauren
Jason Glass

Re: [rentittoday] Long Url from Search Form

By Jason - May 18, 2010

Hi Lauren,

When using action=get, a form will always send a variable for each element in that form, regardless if it's filled in or not.

If post doesn't work for you, you could create a javascript function that will create a query string based on which fields are filled in:

Your form would look something like this:
<form method="get" action="?" onsubmit="submitForm(this);return false; />

Then, in your head tag, you would have a javascript function similar to this:

<script type="text/javascript">
function submitForm(form){
query="tester.php?";
if(form.input1.value!=""){query+="input1="+form.input1.value+"&";}
if(form.input2.value!=""){query+="input2="+form.input2.value+"&";}
if(form.input3.value!=""){query+="input3="+form.input3.value+"&";}

window.location=query;
}
</script>


This script builds a query string based on which fields are entered. Obviously you'll have to change names to match what's on your page.

Hope this helps get you started.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [rentittoday] Long Url from Search Form

By Chris - December 10, 2010

Hi rentittoday,

How about this approach?

<script type="text/javascript">
function submitSearch(form){
path = "viewers/motorcycle_results.php";
query = [];
if(form.category.value!=""){query.push("category="+form.category.value);}
if(form.subcategory_match.value!=""){query.push("subcategory="+form.subcategory_match.value);}
if(form.cities_serviced_keyword.value!=""){query.push("cities_serviced="+form.cities_serviced_keyword.value);}
if(form.state_match.value!=""){query.push("state="+form.state_match.value);}
var url = path + '?' + query.join('&');
window.location = url;
}
</script>


I hoep that helps! Please let me know if you have any questions.
All the best,
Chris