Skip current form URL

As a continuation of Adding values ​​to the query string in the URL , I have a search box that will add additional arguments to the current URL.

http://example.com/?s=original+new+arguments&fq=category

The form code is as follows:

<form id="FilterSearch" method="get" action="http://example.com/search_result.php">

Where search_result.php is just a new page that I created to parse submit and redirect using the new URL.

How to pass the original url to search_result.php so that I can then manipulate the url?

EDIT # 1 : I added hidden input:

<?php $current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>
<input type="hidden" name="current_url" value="<?php $current_url; ?>" />
<input name="send" id="send" type="submit" value="Search" />

My output only adds the arguments to the submit page (search_result.php), not the intended query page.

<?php
if (isset($_GET['send'])){
                $searchField = urlencode($_GET['SearchField']);
                $location =  $_GET['current_url'];
                $location = preg_replace($location, '/([?&]s=)([^&]+)/', '$1$2+'.$searchField);
                header('Location: '.$location);
                }
?>

I am either mistaken, or mistaken, or both!

EDIT No. 2 . The output url looks like:

http://example.com/wp-content/themes/child_theme/search_result.php?SearchField=newTerm&current_url=www.example.com%2F%3Fs%3DoldTerm%26searchsubmit%3D&send=Search

№ 3 URL-, . preg_match , , URL- . , . http://, :

header('Location: http://'.$location);

, , , preg_replace.

+5
3

, .

- :

<input type="hidden" name="current_url" value="(Current URL here)" />

, $_GET $_POST.


, :

echo $location; die; :

$location =  $_GET['current_url'];

, ? , .

+8

$_SERVER['HTTP_REFERER'] search_result.php. - , .

+1

The best way to get the current URL is to create hidden input in that you pass the current URL and catch the server end. those.

<input type="hidden" name="cur_url" value="(your Current URL here)" />
0
source

All Articles