Welcome Guest, Not a member yet? Register   Sign In
Repopulate multiple dropdown after form validation
#1

[eluser]iijb[/eluser]
Hi all,
I have a form with two textboxes, one file field and a multiple dropdown field. My problem is when the form validation fails, textboxes values remained but the multiple select box value clears.
My code for dropdown is here.
Code:
echo form_multiselect('cmbCityIdSelected[]', $cities_options_selected, set_select($cities_options,$cmbCityIdSelected))


Please help me out
Thanks in advance
iijb
#2

[eluser]Aken[/eluser]
form_multiselect's third parameter expects either a string containing a single selected key, or an array of selected keys. The set_select() function returns a string intended to be used within the <option> HTML that specifies if the selected="selected" string should exist or not.

http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]iijb[/eluser]
Hi,
One thing I forgot to mention in my question. I have two multi select dropdown list, in the first list there is some cities(from the db) and after clicking each item, it will added to the second dropdown list. The second dropdown list is clearing after validation fails.
Please help me out.

Thanks again
iijb
#4

[eluser]Sepehr Lajevardi[/eluser]
Fetch the values from $_POST and pass it as the third parameter to the form_multiselect() helper.
BTW, CI Form API library handles all these kinda jobs (and many more) out of the box.




Theme © iAndrew 2016 - Forum software by © MyBB