Is URL parameters okay in HTTP POST requests?
I'm working with some HTML forms and I just want to know if it is okay to use a URL parameters in the action attribute even if the method attribute is开发者_运维技巧 POST?
<form action="index.php?somefield=someval" method="post">
<input name="anotherfield" value="anothervalue" type="text" />
<input type="submit" />
</form>
Well, this works fine, I can get all fields and their values in my postback page but I want to know if I'm breaking some rules, standard or something by doing this? Please, if you can, show some resource that can prove it is okay because I can't find it in W3.org.
As the specifications RFC1866 section 8.2.3 states that:
If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be 'POST'.
To process a form whose action URL is an HTTP URL and whose method is 'POST', the user agent conducts an HTTP POST transaction using the action URI, and a message body of type 'application/x-www-form- urlencoded' format as above. The user agent should display the response from the HTTP POST interaction just as it would display the response from an HTTP GET above.
When sending a POST
request, the form data is actually sent in the body of the request, not in the header. So the request URL (the form's action
) is different from the request body.
The data sent to the server in the background looks like this:
POST /path/script.php?somefield=somevar HTTP/1.1
User-Agent: User-Agent-String/1.0
Content-Type: application/x-www-form-urlencoded
Content-Length: 32
home=Cosby&favorite+flavor=flies
As long as your code is consistent and works you should be fine. Only seperate the parameters if you have a reason to, and then document it so its clear why to anyone who comes along later.
And of course test it to make sure it works. Its probably not standard, but if you have some reason there's nothing to say you can't do it.
It works, but can sometimes be confusing. If your somefield=someval is relevant to your form, it's probably better to do:
<form action="index.php" method="POST">
<input name="somefield" value="someval" type="hidden" />
<input name="anotherfield" value="anothervalue" type="text" />
<input type="submit" />
</form>
But if your somefield=someval is irrelevant from the form then you should keep it as GET so it doesn't become part of your form data.
you can use $_REQUEST["name"] to get values from both get or post mode. Check out for more details
精彩评论