Welcome Guest, Not a member yet? Register   Sign In
set_select on a multiple select box not working
#1

[eluser]carlhussey[/eluser]
I have a Multi-select box that I am trying to re-set once validation fails on the page.

Here is what I have:

Code:
<select name="prevention[]" id="prevention" class="form-control dd ff" placeholder="Select 1 or more options" multiple="multiple">
                     &lt;?php foreach($processes->data as $process){ ?&gt;
                     <option value="&lt;?php echo $process->processID.'"'.set_select('prevention[]',$process->processID); ?&gt;> &lt;?php echo $process->process; ?&gt;</option>
                     &lt;?php } ?&gt;
                  </select>

Is there another way I should be doing this?
#2

[eluser]rufnex[/eluser]
You can do something like that:

Code:
<select name="prevention[]" id="prevention" class="form-control dd ff" placeholder="Select 1 or more options" multiple="multiple">
&lt;?php foreach($processes->data as $process){ ?&gt;
<option value="&lt;?php echo $process->processID; ?&gt;"&lt;?php if(in_array($process->processID, set_value('prevention[]'))): ?&gt; selected="selected"&lt;?php endif; ?&gt;> &lt;?php echo $process->process; ?&gt;</option>
&lt;?php } ?&gt;
</select>

It preselects the values after a submit vaild tested with the validation library.




Theme © iAndrew 2016 - Forum software by © MyBB