Playground

How to implement Google cse with custom searchbox form #codeigniter

Before making the controller and the view, to get its engine id should you enter this url first https://cse.google.com/cse/  .

https://your_domain/search?q=your_query 

View *search form

<form>
<div class="input-group">
<input name="q" required="true" type="text" class="form-control" placeholder="Search...">
<span class="input-group-btn">
<button class="btn btn-theme-bg" type="submit">Go!</button>
</span>
</div>
</form>

Controller *search

$xyz=   $_GET['q'];

$this->meta = array( 'active_menu' => 'search','active_read' => 'search','meta_judul' => $xyz."Search from Entol.net",'meta_tag' => $xyz,'deskripsi' => "Search result of ".$xyz );

$meta = $this->meta;      
$this->load->view('commons/header',$meta);      
$this->load->view('search',$data);      
$this->load->view('commons/footer',$data);  

Result View 

<div class="results-sidebar-box">
<script>
(function() {
  var cx = 'YOUR_ENGINE_ID';
  var gcse = document.createElement('script');
  gcse.type = 'text/javascript';
  gcse.async = true;
  gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
  var s = document.getElementsByTagName('script')[0];
  s[removed].insertBefore(gcse, s);
})();
</script>
<gcse:searchresults-only></gcse:searchresults-only>
</div><!--result box-->

finished , for a demo please do a search on the menu of this website . I hope this helps

About the Author

Entol Fakih

Gairah terbesar Saya adalah hiking ke hutan dan menikmati keindahan alam. Meskipun berjiwa romantis, saya adalah geek keseluruhan seperti anggota tim entol.net lainnya.Hal yang dapat menjauhkan saya dari komputer adalah fotografi.


Entol Fakih