Repopulate a Dropdown |
[eluser]digitaldivaradio[/eluser]
I have two drop down menus that are a simple arrays, occupations and states. This is a new user reg form. Both drop downs are required when the user submits the form. When the user submits and fails validation all my text fields are repopulating, but not the drop-downs. I would like to make it easier on the user. Can you help me find the right way to repopulate a drop down? Here is my code. VIEW Code: $occupation = array( CONTROLLER Code: $this->form_validation->set_rules('occupation', 'Occupation', 'trim|required');
[eluser]danmontgomery[/eluser]
http://ellislab.com/codeigniter/user-gui...elper.html Quote:form_dropdown()
[eluser]digitaldivaradio[/eluser]
I understand that, I know I can set the select value. I want it to repopulate if the form fails with the user's selection. not mine.
[eluser]Jamie Rumbelow[/eluser]
Use the set_select() function in the form validation library. Read the docs on it - it's a really useful little function.
[eluser]danmontgomery[/eluser]
[quote author="digitaldivaradio" date="1276032699"]I understand that, I know I can set the select value. I want it to repopulate if the form fails with the user's selection. not mine.[/quote] So you would pass the submitted values to the view, and use the 3rd parameter of form_dropdown() Code: echo form_dropdown('occupation',$occupation,$this->input->post('occupation'));
[eluser]Lawrence Leung[/eluser]
[quote author="Jamie Rumbelow" date="1276033695"]Use the set_select() function in the form validation library. Read the docs on it - it's a really useful little function.[/quote] I am not sure how to use the "set_select" which mentioned in the document. In the documentation, it used the "set_select" to the "options" one by one. But in the form_dropdown, I passed an array to it. Therefore, I don't understand how to apply the "set_select" in it. I used $this->input->post('xxxxxxx') to re-populate the dropdown form. e.g. <?php echo form_dropdown('article_material', $material_options, $this->input->post('article_material'), 'id="article_material"'); ?> When it is in a update form, which required a default value: <?php echo form_dropdown('article_material', $material_options, $this->input->post('article_material') ? $this->input->post('article_material') : $article['article_material'], 'id="article_material"'); ?>
[eluser]bsauls[/eluser]
This works for me with 2.02 and automatic form validation via config file. Code is from the view within form, form fieldset: Code: <?php $current_year = date("Y"); |
Welcome Guest, Not a member yet? Register Sign In |