How do I use multiple form input so it can be used in a search feature - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: How do I use multiple form input so it can be used in a search feature (/showthread.php?tid=52091) Pages:
1
2
|
How do I use multiple form input so it can be used in a search feature - El Forum - 05-29-2012 [eluser]msank[/eluser] Hi, I am new here, and was needing to figure out how I can pass two values at the same time from two form input fields to a search feature... The values are hidden, and predetermined based on which page the user is on. This is the form: Code: <?php This is the controller: Code: function search() { This is the model: Code: function searchInventory($search) { At this point in time it is only using the last input value (900) to search. I would like it to use both input values at the same time, and display all of the results on the same page. Any help is appreciated! How do I use multiple form input so it can be used in a search feature - El Forum - 05-29-2012 [eluser]ELRafael[/eluser] Code: foreach ( $your_hidden_array as $hi ) : Your model Code: foreach ( $this->input->post('hiddens') as $var ) : How do I use multiple form input so it can be used in a search feature - El Forum - 05-29-2012 [eluser]msank[/eluser] [quote author="ELRafael" date="1338318389"] Code: foreach ( $your_hidden_array as $hi ) : Your model Code: foreach ( $this->input->post('hiddens') as $var ) : Is this going to allow me to use the two different input values at the exact same time? And post results from both values on the same page? How do I use multiple form input so it can be used in a search feature - El Forum - 05-29-2012 [eluser]ELRafael[/eluser] the secret is hiddens[] <- see the []. You'll have an array with all values. I think that it was what you asked How do I use multiple form input so it can be used in a search feature - El Forum - 05-29-2012 [eluser]msank[/eluser] It doesn't like that... I keep on getting an undefined variable error message. I am trying to pass both values at the same time to get one result. How do I use multiple form input so it can be used in a search feature - El Forum - 05-29-2012 [eluser]ELRafael[/eluser] I still believe I answered correct. If you want to pass more than 1 value to the search model, you can do using array in your input tag. Example: Your html Code: <input type="hidden" name="hiddens[]" value="1" /> Your Controller Code: $hiddens = $this->input->post('hiddens'); Code: 1<br /> How do I use multiple form input so it can be used in a search feature - El Forum - 05-29-2012 [eluser]msank[/eluser] It's returning "Array" thus no results. How do I use multiple form input so it can be used in a search feature - El Forum - 05-30-2012 [eluser]ELRafael[/eluser] Now I tested this function, here it's working Your controller Code: class test_array extends CI_Controller { Your view Code: <!DOCTYPE html> How do I use multiple form input so it can be used in a search feature - El Forum - 05-30-2012 [eluser]msank[/eluser] K. Well your code works, but not for what I am trying to do... OR I'm am just blind and can't see what I am missing? Either way I am still getting "Array" as the thing being searched for, and it is not doing anything. Thanks for your help, though! How do I use multiple form input so it can be used in a search feature - El Forum - 05-30-2012 [eluser]ELRafael[/eluser] If you getting "Array" as result, try to dump the var. Assuming your variable is $xpto, try to do: Code: var_dump($xpto); You should see your array's content. You'll probably need to put this array inside a foreach. Try to put your code in pastebin or something like that for a precise help. |