Search code examples
htmlgoogle-custom-search

How to redirect Google Custom Search Engine results to results.php page?


I created a Google CSE and the search box is on the home page of the site. When a user searches, it should redirect them to results.php with the results, however, it redirects them to a cse.google.com/randomurl instead.

It is set up to have the two page format so there should be no problems. I have tried adding an action to my form but no luck.

<form class="form-inline" action="results.php" method="POST">
  <div class="md-form my-0">
    <script async src="https://cse.google.com/cse.js?cx=983049830948390:lxzkzf8ljowm"></script>
    <div class="gcse-searchbox-only"></div>
  </div>
</form>

*I modified my custom search engine URL in this question for anonymity purposes.


Solution

  • The documentation shows it like this:

    <div class="gcse-searchbox-only" data-resultsUrl="YOUR_RESULTS_PAGE_URL"></div>
    

    You have:

    <div class="gcse-searchbox-only"></div>