CodeIgniter Forums
PHP Tags not preserved when passing into a View / Validation on dynamically created select control - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: PHP Tags not preserved when passing into a View / Validation on dynamically created select control (/showthread.php?tid=34026)



PHP Tags not preserved when passing into a View / Validation on dynamically created select control - El Forum - 09-16-2010

[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