Welcome Guest, Not a member yet? Register   Sign In
Repopulate select menus in 1.7
#1

[eluser]Sander Versluys[/eluser]
I've searched the forums and it's been asked before but since 1.7 the validation library has changed, I can't get it to work.

Code:
<select name="myselect">
  <option value="one" &lt;?php echo set_select('myselect', 'one', TRUE); ?&gt; >One</option>
  <option value="two" &lt;?php echo set_select('myselect', 'two'); ?&gt; >Two</option>
  <option value="three" &lt;?php echo set_select('myselect', 'three'); ?&gt; >Three</option>
</select>

This code is from the docs. I do not understand how the function can know which option to select. Can somebody explain this to me...?

Here's an example of what I'm trying todo:

Code:
<select name="level">
  <option value="0" &lt;?= set_select('level', '0'); ?&gt; >Gebruiker</option>
  <option value="1" &lt;?= set_select('level', '1'); ?&gt; >Partner</option>
  <option value="2" &lt;?= set_select('level', '2'); ?&gt; >Administrator</option>
</select>

In my controller I pass the object $user, wich has the property 'level', to the view. The option with the same level as in the object should be selected.

Any help would be greatly appreciated! Thanks!
#2

[eluser]crumpet[/eluser]
it compares the it to the data $this->_field_data[$field]['postdata']
which is a variable the validation class sets. What you have done should work...if you are using the rest of the validation library
#3

[eluser]Sander Versluys[/eluser]
Thanks for the info!

Still, i can't seem to get it to work although i use the validation library as described in de docs. But offcours i know there must be on error on my side somewhere.

I used the form_dropdown() function from the form helper and that did the trick for me...
#4

[eluser]McNoggin[/eluser]
Did you have a rule setup for level? If not then it won't work.




Theme © iAndrew 2016 - Forum software by © MyBB