02 Votes

PHP: Form: Submit data via POST and GET at the same time

Question by Guest | 2012-06-16 at 21:30

I just wonder, whether it is possible in principle to transfer data from an HTML form with POST and send other variables with GET in the URL (so that it can be seen in the browser) at the same time.

The background: The POST variables should be further processed in a PHP script, while the GET variables are used to display the page. On my HTML page, I have multiple forms, so that it depends on the GET variable, to which page is forwarded.

ReplyPositiveNegativeDateVotes
2Best Answer4 Votes

Just write the variables to be transmitted via GET into "action" in your form. The rest of the form remains unchanged.

Here's an example:

<form action="page.php?getvar=xyz" method="post">
  <input name="postvar1" value="">
  <input name="postvar2" value="">
</form>

The PHP Script can look something like this:

$var1 = $_POST['postvar1'];
$var2 = $_POST['postvar2']; 
$var3 = $_GET['getvar'];

With this, you have transferred two variables with POST and one variable with GET.
2012-06-18 at 13:35

ReplyPositive Negative
-11 Vote

You are correct. It works fine. I've been using it successfully with an ajax search form, and dynamic codes sent over to the receiving php script.
2020-02-11 at 00:15

Positive Negative
Reply
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.