Passing field value to URL |
[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";
[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.
[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. |
Welcome Guest, Not a member yet? Register Sign In |