anon271334
anon271334

Reputation:

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=someaction as a part of the url, but I don't want to have any hidden form fields.

Can this be done?

Thanks!

Upvotes: 2

Views: 186

Answers (3)

eckes
eckes

Reputation: 67047

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.

Upvotes: 1

Lior Cohen
Lior Cohen

Reputation: 9055

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'];

Upvotes: 0

Spiny Norman
Spiny Norman

Reputation: 8327

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']).

Upvotes: 2

Related Questions