![]() |
Passing field value to URL - 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: Passing field value to URL (/showthread.php?tid=26004) |
Passing field value to URL - El Forum - 01-03-2010 [eluser]sdotsen[/eluser] Ultimately I would like the following: www.domain.com/tags/orange www.domain.com/tags/apple One can view all users tagged w/ a specific word by inputting the URL (shown above) or searching for it via a search box. The code works if I type in the URL by hand, but ultimately I would like to put a search field and have the user search for a tag. Let's say I have the following code to display the search box on one of my pages. Is it possible to pass the "tag" field value into the URL? Code: <?=form_open('tags/');?> Now the code for my "tags" class Controller (snippet): Code: function index() { Model (snippet): Code: function searchByTag($tag) { Routes: Code: $route['tags'] = "tags/index"; Passing field value to URL - El Forum - 01-03-2010 [eluser]Sbioko[/eluser] Add the id attribute to your input tag and remove form_open function. And on onsubmit event get the field's value and redirect the page. I will not provide you full code, because ci filters HTML. Passing field value to URL - El Forum - 01-03-2010 [eluser]brianw1975[/eluser] if it weren't apparent, what's basically being said above is this: don't use a regular form submit, use javascript to grab the text from the input field and use it to do a location(?).href change using javascript. Personally, I would do a regular submit, have the code see if there are any tags at all that match and if so then use a redirect to the proper url, if no matching tags then provide some other content rather than relying on the javascript to always work. |