0 2 Votes

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

Question by Guest | 16/06/2012 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.


Stefan Trost

Show Profile | Message
2Best Answer
4 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="">

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.
18/06/2012 at 13:35

ReplyPositive Negative
00 Votes

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.
11/02/2020 at 00:15

Positive Negative

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.


Ask your own question or write your own articles on askingbox.com. How to do.