![]() |
SOLVED: Dynamically dropdown <select> form validation - 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: SOLVED: Dynamically dropdown <select> form validation (/showthread.php?tid=41241) |
SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-02-2011 [eluser]atno[/eluser] Hi, I have a <select> that is created dynamically from a database and it must validate to check if any option is selected. The options are about 58 and only one can be selected. If a user selects something but forgot to enter his/her name on submit the select will be reset, he/she will type his/her name and now when submit is pressed again there will be a new error showing that no option is selected! I read the user_guide but I don't get it how to form_validate a <select> with so many dynamically generated options. What I understand is that every set_select() but be entered manually. Is there a way to do it and i have missed the big picture? Here's the code Code: <select name="test" size="1"> Cheers, atno SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-02-2011 [eluser]Armchair Samurai[/eluser] There are a couple of ways to approach this. First, you can do the foreach() approach and just call set_select on each loop: Code: <select name="test" size="1"> The other option would be to use form_dropdown() and call set_value(), but you'd need to put the array in a format which form_dropdown can understand: Code: <?php $result = $test->result(); SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-02-2011 [eluser]atno[/eluser] Will any of these methods auto select the previously (before page update) selected option? SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-03-2011 [eluser]Rok Biderman[/eluser] I know it's offtopic, but i actually see a dropdown in the title instead of select tag. Might be wise to fix it. SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-03-2011 [eluser]atno[/eluser] [quote author="Coccodrillo" date="1304425312"]I know it's offtopic, but i actually see a dropdown in the title instead of select tag. Might be wise to fix it.[/quote] What do you mean? SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-03-2011 [eluser]danmontgomery[/eluser] All you need is an option up top with a blank value, and you can set the field as required. I prefer form_dropdown(), as well. Code: $options = array('' => 'Select One'); SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-03-2011 [eluser]atno[/eluser] Both foreach() and form_dropdown() are working but form_dropdown() is clearer to read. Thank you both Armchair Samurai, noctrum. atno SOLVED: Dynamically dropdown <select> form validation - El Forum - 05-03-2011 [eluser]Rok Biderman[/eluser] [quote author="atno" date="1304441236"][quote author="Coccodrillo" date="1304425312"]I know it's offtopic, but i actually see a dropdown in the title instead of select tag. Might be wise to fix it.[/quote] What do you mean?[/quote] I mean, this happens to rss feeds, because select tags don't get escaped (screenie attached below). I said it was O/T ![]() SOLVED: Dynamically dropdown <select> form validation - El Forum - 09-11-2012 [eluser]Unknown[/eluser] Code: <select name="test" size="1"> same one... But i need to display the selected value in 'text' Box??? |