0

after submitting a form I get redirected to the same page because I settled the form action as $_SERVER['PHP_SELF'] but I've got the problem I need to be redirected to the full url which pass the id and cat GET variables.

I think I can easily solve it by adding to the server variable something like

.'?id='.$_GET['id'].'&cat='.$_GET['cat']

but I would like to know if there is something similar to PHP_SELF, but which keep the full url with the GET variables.

anubhava
  • 761,203
  • 64
  • 569
  • 643
GabAntonelli
  • 757
  • 2
  • 9
  • 26
  • if you leave out the action/url the form will be submitted to the current URL. you should get the params with it. I'd consider sending them with post though. If there aren't any spesific reasons you want the params in the address field. – JimL Sep 11 '13 at 17:43
  • 1
    Do a `print_r($_SERVER);` to determine the best variable to use. Generally you'll have access to the full requested URL including query-string parameters and hash. – Jasper Sep 11 '13 at 17:43
  • possible duplicate of [PHP Get the Full URL](http://stackoverflow.com/questions/6768793/php-get-the-full-url) – John Conde Sep 11 '13 at 17:43

3 Answers3

5

You can just put an empty form action like in the following example:

<form action="" method="POST">

All GET parameters will be preserved

Exwolf
  • 157
  • 1
  • 12
1

The form submit to the current page by default. You could try:

<form action="" method="GET">
   <input type="hidden" name="id" value="some"/>
   <input type="hidden" name="cat" value="value"/>
</form>

domain.com/?id=some&cat=value
rodrigoio
  • 93
  • 4
  • thanks, but my question was different, I already had a way to pass again the data, adding again the values to the url. I was asking if is there any shorter way whith a server variable different from php_self – GabAntonelli Sep 11 '13 at 17:58
  • @Jasper told the best way to discover which variable you need. – rodrigoio Sep 11 '13 at 18:29
0

Change the sending method of the form from POST to GET. http://www.w3schools.com/tags/att_form_method.asp