Submitting variables in POST
I have a form that sends stuff like names and email and a message and I get it with $_POST['etc'];
- But, I also want to send action=som开发者_高级运维eaction as a part of the url, but I don't want to have any hidden form fields.
Can this be done?
Thanks!
Yep, just add it to your url: <form action="url.php?action=someaction" method="post">
. You can retrieve them in your php script using $_GET
(in this case, $_GET['action']
).
action=someaction
cannot be read by $_POST['whatever']
because it's submitted in a GET-Request. You can access GET and POST variables by using $_REQUEST
instead of $_GET
and $_POST
.
To form the request, follow the answer of Spiny Norman.
If I understand you correctly, you simply need to add ?action=someaction to the action attribute of your form tag. These would be fetched from PHP by using $_GET instead of $_POST.
Example:
<form action="http://example.com?action=someaction">...</form>
and to get the value:
$action = $_GET['action'];
精彩评论