The CodeIgniter documentation is vague on how to set the default value in a select tag when you are using the form helper. There’s a third parameter to the
set_select method that’s a boolean.
I recommend using something like the following code snippet:
<select class="form-control" name="email"> <option value="">None</option> <?php foreach ($emails as $option): ($option == $userEmail) ? $selected = TRUE:$selected = FALSE; ?> <option <?=set_select('email', $option, $selected)?>><?=$option?></option> <?php endforeach;?> </select>
So you have to check the value of the
$option variable with each iteration of the loop and if it matches another variable (which you should set in your controller) it sets the TRUE that the
set_select method requires.