views:

57

answers:

2

I've got a website where URLs are rewritten in this format:

http://www.example.co.uk/module/page/query/
http://www.example.co.uk/index.php?m=module&p=page&q=query

Which gives rise to pages such as:

http://www.example.co.uk/schools/view/495/
http://www.example.co.uk/schools/search/park+lane/

Is there any way to make it so that a form (submitting via GET) can submit to the rewritten URL, or is this something I'd need to implement with Javascript?

+2  A: 

I wouldn't recommend doing this with JavaScript if it is in any way fundamental to your system, in fact i wouldn't recommend doing this with JavaScript at all as there is really no need. You could create a script that your form submits to and then header redirect to the mod rewritten URL from there. For example:

// searchtransform.php?search=foo
$searchterm = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_STRING);
header("Location: /search/".$searchterm);
seengee
+1  A: 

The answer from @seengee would work too, but this is how I would do it in javascript: You could submit the form via javascript and set the action to the url there:

<input type="button" onclick="formSubmit();"/>

function formSubmit()
{
    document.form1.action = "anotherpage.html";
    document.form1.submit();
}
Jeff V
Although the user might have JS disabled. Especially with Firefox plugins like NoScript - I wouldn't presume that this is very uncommon. Serverside is definitely more preferable for this.
Dan
That is an interesting question. I can't imagine most of the users turning off JS anymore. That argument (along with cookies) was prevalent in the 90's but I haven't heard much of it lately.
Jeff V
@Jeff - must say i disagree with this. i can give one clear example of a "user" that will have JavaScript turned off and thats the googlebot which does like to crawl GET forms for search results.http://googlewebmastercentral.blogspot.com/2008/04/crawling-through-html-forms.html Not to mention users with screenreaders, people using NoScript extension. Need i go on?
seengee
@Dan - If you turn off JS than jQuery wouldn't work right? You might be right, I just remember back in the day even the average user was concerned with JS. I don't see that being an issue except now in the niche tech community. Just my opinion. Most sites I see have some sort of JS in them and most sites are implementing even more with jQuery and AJAX.
Jeff V
@Jeff - In the most case, you're right - most users won't have JS disabled. However, as I mentioned before - the NoScript plugin is very popular. No, jQuery wouldn't work with JS turned off - as jQuery is written in Javascript. It's just something to bare in mind that's all - it really depends on how important the consequences are for system if the user has JS disabled.
Dan