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");
精彩评论