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¤t_url=www.example.com%2F%3Fs%3DoldTerm%26searchsubmit%3D&send=Search
№ 3
URL-, . preg_match , , URL- . , . http://, :
header('Location: http://'.$location);
, , , preg_replace.