Suppose we are on the page (no matter what) and we have in the address bar something like: https://site.com/app/backend.php?param1=abc¶m2=cde

On the page there is a form with <input name='param3'> sending which you should go to the same page, with the first two parameters + the third one should be attached to them. Those. finally, after submitting the form, we should go to https://site.com/app/backend.php?param1=abc¶m2=cde¶m3=aaa

My decision:

 <? $repeatRequest = http_build_query($_GET); ?> <form class="form-inline" action="backend.php?<?=$repeatRequest?>" method="get"> <div class="form-group"> <label>Страница: </label> <div class="input-group"> <input type="text" name="param3" class="form-control" size="2" value="<?=$_GET['offset']/20?>"> <span class="input-group-btn"><button class="btn btn-default" type="submit">перейти</button></span> </div> </div> </form> 

But ultimately we get to https://site.com/app/backend.php?param3=aaa

What is the trouble and how to fix it?

  • From the form there is a request to site.com/app/backend.php?param3=aaa , and not to site.com/app/… . That's why the whole thing. - labris
  • @labris did not quite understand. How to avoid it and do it the way I need it? - Ivan Blohin
  • The current address of the page + param3 = aaa should be passed from the form to the action. - labris
  • @labris I understand. But no matter how I try, it does not work. Can I code? - Ivan Blohin
  • It is difficult to say how the entire URL is formed in you, just try to define it and also transmit it in the form, for example through $ _SERVER ['REQUEST_URI'] or $ _SERVER ['QUERY_STRING']. - labris

1 answer 1

As said above, it was easier to gash a crutch on JS. There is an input with a button

 <input id="page-number" type="text"> <button onclick="paginationManager()" type="button">перейти</button> 

When a user changes something in input and presses a button, the following script is executed:

 function paginationManager(){ /*Получаем содержимое адресной строки*/ var location = window.location.toString(); /*Получаем значение, которое ввел пользователь*/ var page = document.getElementById("page-number").value; /*Тут будет ссылка, по которой нас перенаправит*/ var link; /*Если параметр page-number (тот самый доп параметр) уже есть, то изменяем его (\d) означает цифру. Иначе к текущим параметрам "клеим" дополнительный */ /*Это нужно, чтобы избегать повторений в адресной строке але &page-number=3&page-number=5*/ if (location.search(/page-number=\d*/) != -1) { location = location.replace(/page-number=\d/, "page-number=" + page); link = location; } else { link = location + "&page-number=" + page; } /*Переадресация на сформированную ссылку*/ window.location.href = link; } 

The downside is obvious - js is disabled - will not work. I would be glad to see here a normal solution.