Form drop_down problem - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Form drop_down problem (/showthread.php?tid=44056) |
Form drop_down problem - El Forum - 08-01-2011 [eluser]Michal1[/eluser] Hello guys I trying to use dropdowns in a simple way and I am having problems with them. I have a controller site and inside of function index I have: Code: $shirts_on_sale = array('small', 'large'); then in admin_view I have Code: <?php echo form_dropdown('shirts', $shirts_on_sale, 'large'); ?> But I receive an error Code: A PHP Error was encountered why is that? Thanks for any input Form drop_down problem - El Forum - 08-01-2011 [eluser]toymachiner62[/eluser] Did you load the form helper? Form drop_down problem - El Forum - 08-01-2011 [eluser]danmontgomery[/eluser] Code: $data = array('shirts_on_sale' => array('small', 'large')); Form drop_down problem - El Forum - 08-01-2011 [eluser]Michal1[/eluser] [quote author="noctrum" date="1312241160"] Code: $data = array('shirts_on_sale' => array('small', 'large')); Thank you but I dont understand why it has to be in this way? Form drop_down problem - El Forum - 08-01-2011 [eluser]Michal1[/eluser] Because even if I have this it does not work Code: $options = array( and then in admin_view: Code: <?php echo form_dropdown('shirts', $options, 'large'); ?> Form drop_down problem - El Forum - 08-01-2011 [eluser]Michal1[/eluser] huh anyone? :/ Form drop_down problem - El Forum - 08-01-2011 [eluser]Aken[/eluser] You need to read more about how dynamic data is passed to views: http://ellislab.com/codeigniter/user-guide/general/views.html Form drop_down problem - El Forum - 08-02-2011 [eluser]Michal1[/eluser] huh,I know how dynamic data are passed to views. I passed as an array of course here: Code: $this->load->view('admin_view',$options); So there must problem in a view in this line right? Code: <?php echo form_dropdown('shirts', $options, 'large'); ?> Form drop_down problem - El Forum - 08-02-2011 [eluser]LuckyFella73[/eluser] Quote:Because even if I have this it does not work Should look like: Code: $data['options'] = array( It's basically the same noctrum told you - I just tried to make it easier (visually) It's important for you to understand that you send an array to the view (in my example "$data") which keys are usable as variables/arrays in your view. Veery basic example: Code: // controller: Hope that makes it a bit clearer. Form drop_down problem - El Forum - 08-02-2011 [eluser]Michal1[/eluser] Ah thanks, I got it know. |