Help Needed with Dropdown Selection - 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: Help Needed with Dropdown Selection (/showthread.php?tid=35211) |
Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]TerryT[/eluser] Finally wasted enough hours beating this around. Any help would be appreciated. I have an input form dropdown. I want the user to select a project off the dropdown before the data gets posted to the database so the items can be posted to the right project. View Code: Code: <div class='dropdown'> Controller Code: Code: $selection = 0; It doesn't appear that a project ever gets selected. On a side note, how would you print out the $selection to see what is going on? Tried print_r in the controller and form and nothing. Thanks. Terry Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]LuckyFella73[/eluser] You can set a default entry for your dropdown where the value is '' - for example: Code: $options = array( In your controller set the validation rule for that element like: $this->form_validation->set_rules('select_name', 'Example Select', 'required'); Don't forget to load the form validation class of course.. Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]TerryT[/eluser] Now the validation is forcing a selection, but despite selecting a project in the dropdown, I get a validation error message stating the Project field is required. Terry Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]LuckyFella73[/eluser] If you set the rule only to "required" and get that message than your selected option has no value or you have an other error - maybe misspelled something? Can you show your controller and view script - at least the parts that are involved in that problem? Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]TerryT[/eluser] The dropdown only shows the projects that each user is involved in. $data['proj_menu'] feeds the dropdown and works correct. Only an individual user's projects are shown. Here's the controller part. It is part of the add_item method: Code: $this->userid = $this->session->userdata('user_id'); Here's the view part. : Code: <div class='dropdown'> Terry Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]LuckyFella73[/eluser] Your select element is not inside your form - that's why there is no POST-value for "proj_select" and it's empty whatever you select. The rules and all I can see seems to be fine. Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]TerryT[/eluser] That fixed it! That was a hard lesson over a bunch of hours that won't be forgot. Thanks for all the help. Now if I can figure out how to have the dropdown box maintain the selection when I click into the other input fields, I will be all set. Thanks again. Terry Help Needed with Dropdown Selection - El Forum - 10-22-2010 [eluser]LuckyFella73[/eluser] Glad I could help! |