tags:

views:

169

answers:

2

This seems so simple but I can't remember how I've done it before.

Using PHP I'm posting a form from mysite.com/?x=y and want the resulting page to be mysite.com/?x=y&formx=formy...

Options I've tried don't quite give the desired result:

action - setting action="?x=y" clears the get variables if method="get" in place of those in the form. Prior knowledge of the get variables are also required.

method - although it seems logical to set method="get", this passes the form variables but clears any placed in action. Setting method="post" retains the current get variables but doesn't add the form variables/values.

Hidden field(s) - All get variables/values can be in hidden fields with method="get". This requires prior knowledge of the get variables and a lot of duplication if there are a lot of variables or forms. This so far is the closest solution.

+2  A: 

Just set the form's "method" attribute to "get" instead of "post".

Example:

<form action="?x=y" method="get">
<input type="text" name="query" size="20">
<input type="submit" name="submit" value="Go">
</form>
Andrew Medico
+1  A: 

I suppose you could :

  • either pass those variables as <input type="hidden" name="x" vaue="y" /> in your form.
  • or, maybe this might work : use "mysite.com/?x=y" as action for your form : with a bit of luck, those parameters will remain when the browser will post your form -- you should try, but it might work.

Of course, if you want those parameters to appear in the URL of the destination page, you'll have to use the GET method for your form.

Pascal MARTIN