Welcome Guest, Not a member yet? Register   Sign In
Form Validation - set_select - fill from database
#1

[eluser]Unknown[/eluser]
I am working on a form with the help of the form helper. What i wan't to do is using the form validator to validate the form and if the user is editing the form the select box needs to be set from a value that I retrieve from the database.

I have used the following code to see if it is going to work but it seem that I am doing something wrong.

Code:
<select name="primaryFocus">
                &lt;?php foreach($primaryFocusVals as $val => $text): ?&gt;
                <option val="&lt;?=$val?&gt;" &lt;?=set_select('primaryFocus', $val)?&gt;>&lt;?=$text?&gt;</option>
                &lt;?php endforeach; ?&gt;
            </select>

Code:
<select name="primaryFocus">
                &lt;?php foreach($primaryFocusVals as $val => $text): ?&gt;
                <option val="&lt;?=$val?&gt;" &lt;?=set_select('primaryFocus', $val, ($primaryFocus == $val)? TRUE : FALSE)?&gt;>&lt;?=$text?&gt;</option>
                &lt;?php endforeach; ?&gt;
            </select>

Both methods echo selected="selected" to every option. Does anyone have a solution for my problem?

With Regards,

Flex1986
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

Is the form validation class loaded at the top of your controller method. It's quite an easy mistake to make by thinking it's only needed when the form is submitted.




Theme © iAndrew 2016 - Forum software by © MyBB