2

I've set up a search box on the homepage, that should link into the Opencart search by passing a URL.

The problem I'm having is that the resulting URL is always unencoded:

store/index.php?route%3Dproduct%2Fsearch%26filter_name=test

What I'm aiming for is

store/index.php?route=product/search&filter_name=test

My current code is:

<?php
$storesearch = $_REQUEST['store-search'] ;
$filter = 'route=product/search&filter_name';
$filtered = html_entity_decode($filter);
?>
<form id="store" method="GET" action="http://localhost/vinmobile/store/index.php?<?php echo $storesearch; ?>">
<input type="text" id="store-search" name="<?php echo $filtered; ?>" value="Store Search" onclick="this.value = '';">
<input type="submit" name="" value="Search">

</form>
<?php echo $filtered; ?> // Just to show it onscreen to make sure it's written correctly

I've tried encode, decode, html_entity_decode, urldecode, rawurldecode... I've tried the form method as GET, POST I've tried the variable declaration as $_REQUEST, $_GET, $_POST

Every time, I still end up with the url looking like:

store/index.php?route%3Dproduct%2Fsearch%26filter_name=test

I'm sure it's something simple I've missed, but I 'think' I've tried everything and would be very grateful if someone could point me in the right direction.

Cheers

webecho

Arghavan
  • 1,125
  • 1
  • 11
  • 17
webecho
  • 79
  • 9
  • Have you tried doing a `utf8_decode` first? https://stackoverflow.com/a/1756925/6577664 – Joshua May 26 '17 at 08:43
  • I hadn't, but it still didn't work... `$filter = 'route%3Dproduct%2Fsearch%26filter_name'; $filtered = utf8_decode(urldecode($filter));` Also tried: `$filter = 'route=product/search&filter_name'; $filtered = utf8_decode(urldecode($filter));` – webecho May 26 '17 at 08:50
  • What about adding the route to the form action? i.e. `action=index.php?route=product/search` then give the your search field a name that stays consistent like `search` – Lucas Krupinski May 28 '17 at 13:49
  • Thanks Lucas Yes, already tried that way (using filter_name) but the whole thing is re-written by opencart so it doesn't work. – webecho May 29 '17 at 03:50

1 Answers1

0

Ended up using Javascript instead and it works perfectly:

`<script>
function process()
{
var url="store/index.php?route=product/search&filter_name=" + document.getElementById("filter").value;
location.href=url;
return false;
}
</script>
<form id="store" onSubmit="return process();">
<input type="text" name="filter" id="filter" value="Store Search" onclick="this.value = '';"> 
<input type="submit" value="Search">
</form>`

Thanks for your suggestions though

webecho
  • 79
  • 9