Reputation: 1151
I've seen questions like this but none really answer this specific question. Can you include get variables in the form tag's action attribute? For example:
<form action="script.php?id=4" method="get">
<input type="text" name="thing" value="temp">
<input type="submit">
</form>`
This would theoretically result in the get request: script.php?id=4&thing=temp
I'm aware that you can simply do this:
<form action="script.php" method="get">
<input type="hidden" name="id" value="4">
<input type="text" name="thing">
<input type="submit">
</form>`
But I'm curious as to if the previous method is at all possible.
Upvotes: 2
Views: 8932
Reputation: 323
Yes you can absolutely do that! You can append any GET variables in your action attribute and just see your URL,it'll clearly show you the changes.
The best use of this strategy is when you want both $_GET and $_POST variables to be there.That is,you can pass variables as GET variables by appending them to action attribute and you can simultaneously pass POST variables through the form(obviously with method attribute set as "post").
Upvotes: 2