i have a form that uses a drop down and im using codeigniter , form helper and form validation so when i get a validation error in my form , all the correctly entered fields are populated using set_value of codeigniter , however this doesnt work for dropdown
im doing :
<?php echo form_dropdown('mid', $id_map, set_value('mid'), 'id="mid"') ?>
when get error in form , always the first value of dropdown is selected and not previously set
Any ideas , what am i doing wrong?
If you do not have a validation rule on the actual dropdown field, then
is sufficient.
What about if the the form select content is selected from a foreach loop like this
It's because you have to use the set_select() function , not the set_value();
You can check that here: http://codeigniter.com/user_guide/helpers/form_helper.html
And the right syntax:
EDIT :
If you have a default value, that should go in the 2. parameter for set_select.
I hope this will work.
The correct method to use
set_select()
isSo Andras Ratz method/answer won't work.
Your method is correct.
However remember that
set_value()
is only going to return the value if you have setup a validation rule for it, in your case formid
. You could try as below -or just set a validation rule for
mid
too