CodeIgniter Forums
form GET - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: form GET (/showthread.php?tid=2356)



form GET - El Forum - 07-31-2007

[eluser]AndyBrandy[/eluser]
Hi,

how can i easily make search form like www.google.com?

Because i have problem when data were send, than page http://example.com/search?q=ci
is not found... Only with <form method=POST> ?


form GET - El Forum - 07-31-2007

[eluser]Michael Wales[/eluser]
I was creating a Wiki in Code Igniter at one time. I used Routing and some.htaccess magic to send any request that didn't have a corresponding controller to the result method within my search controller. So, a URL like domain.com/code_igniter would be sent to my method as result('code_igniter').

Code:
<?php
  class Search extends Controller {
    function Search() {
      parent::Controller();
    }

    function index() {
      $this->load->library('validation');
      // ----
      // All your validation stuff would go here
      // ----
      if ($this->validation->run()) {
        // I slugged the search term to remove spacing and special chars - whatever
        redirect($this->input->post('q'));
      } else {
        $this->load->view('search');
      }
    }

    function result($q) {
      // Pull down my wiki page for the q variable (which is a slug of the search term)
    }
  }
?>