views:

129

answers:

3

Hey, so this is one of those questions that seems obvious, and I'm probably going to feel stupid, but here goes:

I'm doing a CodeIgniter site with a search. Think of a Google type input, where you'd search for "white huskies." I have a search results page that takes a URI (MySite.com/dogs/white huskies), and takes the third part, and performs the search on that term. I'd like this to be done in the URI, and no by POST so my users can bookmark results.

The problem I'm having is how to get that search button directed to Mysite.com/dogs/WHATEVER IS IN THE INPUT. How do I get the what is in the input part into the anchor href? I know I could do this with javascript, but I've heard it's bad practice to force people to have javascript for things this small.

Thanks for the help!

A: 

You could have an intermediate POST page that collects the form inputs and concatenates them into a valid URL which you can then redirect to. I'm not sure if this is good or bad SEO practice however, but I can't see another way of doing this without some Javascript intervention.

Perhaps you could look at doing the intermediate POST page which takes the values are redirects you to /search/dog/white/huskies, but also have a Javascript equivalent that does this on the fly on the form submit and does a window.location refresh to the same /search/dog/white/huskies?

Just my 2 pennies worth ;)

Andy Copley
A: 

Read: http://stackoverflow.com/questions/1860600/form-redirect-to-url-containing-query-term-pure-html-or-django

(asked for Django, but answer fits here too)

Adam Kiss
A: 

It is possible to have CodeIgniter work with $_GET variables and URI segments securely.

A work around I have used in the past is to have the search term collected using POST, parse the required URL for use with URI segments and then redirect your user to this page.

$url = 'http://mysite.com/search/' . urlencode($_POST['query']);

redirect($url);

This shouldn't effect SEO but something like the URL of a search result is unlikely to have any effect on SEO anyway. Clean URLs are only really meant to be used for permanent content. If you're going to be displaying the search term on the page, remember to use xss_clean(), seen a few people make this fatal mistake before.

The website-lab