开发者

Submitting a form via GET to a rewritten URL

开发者 https://www.devze.com 2023-01-07 17:21 出处:网络
I\'ve got a website where URLs are re开发者_运维知识库written in this format: http://www.example.co.uk/module/page/query/

I've got a website where URLs are re开发者_运维知识库written 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?


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);


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消