I have a div containing a search box:
<div id="searchbox">
<?php echo form_open('places/search/sort_by/id/sort_order/desc/term/'.$this->input->post('term')); ?>
<?php echo form_label('Search for', 'term'); ?>
<?php echo form_input('term', set_value('term'), 'id="term"'); ?>
<?php echo form_submit('submit', 'Search'); ?>
<?php echo form_close(); ?>
</div>
In the input the user can type in a search term, which will be given to the controller using $this->input->post(‘term’) which then passes to the model to query the database. Now after typging in the search term and submitting the form, I want the url to end with the search term ie. places/search/sort_by/id/sort_order/desc/term/dinosaur if ‘dinosaur’ was the search term. How can I do this?
Right now the code above passes the POST to controller, but the url right after submitting the form is just places/search/sort_by/id/sort_order/desc/term/. Then if the user searches for another term say ‘cats’, after submitting the url becomes places/search/sort_by/id/sort_order/desc/term/dinosaur when the search term is actually ‘cats’.
How can I solve this?
In other words, this is the behavior i want
- URL is places/search/sort_by/id/sort_order/desc/term/ and search box is empty
- ‘Dinosaur’ is typed into search box, and press submit
- URL is now places/search/sort_by/id/sort_order/desc/term/dinosaur and search box contains ‘dinosaur’
- ‘cats’ is typed into search box, and press submit
- URL is now places/search/sort_by/id/sort_order/desc/term/cats and search box contains ‘cats’
This is what I am getting with the above code
- URL is places/search/sort_by/id/sort_order/desc/term/ and search box is empty
- ‘Dinosaur’ is typed into search box, and press submit
-
URL is now places/search/sort_by/id/sort_order/desc/term/ and search box contains ‘dinosaur’
-
‘cats’ is typed into search box, and press submit
- URL is now places/search/sort_by/id/sort_order/desc/term/dinosaur and search box contains ‘cats’
Try this…
Then in the controller that accepts it…