Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple Search: Passing Form Variable to URI Using CodeIgniter

I have a search form on each of my pages. If I use form helper, it defaults to $_POST. I'd like the search term to show up in the URI:

http://example.com/search/KEYWORD

I've been on Google for about an hour, but to no avail. I've only found articles on how $_GET is basically disabled, because of the native URI convention. I can't be the first person to want this kind of functionality, am I? Thanks in advance!

like image 931
jmccartie Avatar asked May 09 '26 17:05

jmccartie


1 Answers

There's a better fix if you're dealing with people without JS enabled.

View:

<?php echo form_open('ad/pre_search');?>
   <input type="text" name="keyword" />
</form>

Controller

<?php
    function pre_search()
    {
        redirect('ad/search/.'$this->input->post('keyword'));
    }

    function search()
    {
        // do stuff;
    }
?>

I have used this a lot of times before.

like image 171
Teej Avatar answered May 11 '26 06:05

Teej



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!