Welcome Guest, Not a member yet? Register   Sign In
PHP Tags not preserved when passing into a View / Validation on dynamically created select control
#1

[eluser]osfan[/eluser]
Hi Guys,

I must be missing something, what I am tring to do is dynamically build a select control to display in my view, simple enough, but I also want to enable validation on the options so that if the user doesn't fill in the form correctly, the value of the select is preserved.

This is easy enough if the select control is static, and placed in the view itself, but when I generate the relevant code, and pass it to the view the Php tags seem to get replaced (possibly by < &gtWink, and the code doesn't work. I have tried html_entity_decode to no effect, I must be missing something obvious ?

Code goes like this:

Code:
$list = $this->example_model->get_examples_list();
$form = '<select name="exampleid" id="exampleid">';
if ($list) {
    foreach ($list as $row) {
        $form .= '<option ' . '&lt;?php= set_select("exampleid", "'.$row->example_id.'"); ?&gt;' . '  >' . $row->example_name . '</option>';
    }  
}
$form .= '</select>';

The area that I am having difficulty with is
Code:
&lt;?php= set_select("exampleid", "'.$row->example_id.'"); ?&gt;

What I want to pass to a view is options similar to
Code:
<option &lt;?= set_select("exampleid", "1"); ?&gt; >Example 1</option>
<option &lt;?= set_select("exampleid", "2"); ?&gt; >Example 2</option>

Could anyone shed any light, or suggest a better way to achieve my goal please ?

Many thanks




Theme © iAndrew 2016 - Forum software by © MyBB