开发者

Mod Rewrite and search query string

开发者 https://www.devze.com 2023-04-04 04:54 出处:网络
To search something, user need to use following URL: http://.../results/query/something I got my text input, in which user type the string to be posted, but it looks then following:

To search something, user need to use following URL:

http://.../results/query/something

I got my text input, in which user type the string to be posted, but it looks then following:

http://.../results/query/?query=something

I've tried to change the 'post method' type, but doesn't bring any good results. How can I开发者_开发知识库 do that, so it'll look like that?

http://.../results/query/something


<form id="myform" method="post" action="/">
<input type="text" id="query" name="query" />
<input type="submit" name="submit" onclick="return go();" />
</form>

<script type="text/javascript">
function go(){
    var query = document.getElementById('query').value;
    document.getElementById('myform').action = 'http://yourdomain/results/query/'+query;
}
</script>


Simple answer:

  • Use method="post"

  • Construct the URL with PHP after the form is posted, using urlencode() and any other appropriate sanitization on the value.

  • Redirect to the page you want.

 $query = isset($_POST['query']) ? urlencode($_POST['query']) : '';
 header("Location: results/query/$query");
0

精彩评论

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