Hello all, I have problems with set_select() in an
edit form.
I load data for an entity call edition and then call the view
Code:
$model = model('App\Models\EditionModel');
$data['edition'] = $model
->select('editions.*, cfg_courses.name as name, cfg_courses.certificationduration as certificationduration')
->join('cfg_courses', 'editions.cfgcourse_id = cfg_courses.id')
->where('editions.id',$edition_id)
->first();
if (strtolower($this->request->getMethod()) == 'get')
{
return view('edition/edit', ['data' => $data]);
}
In the view i put the code:
Code:
<div class="col-2">
<label for="opensubscriptions">Iscrizioni</label>
<select class="form-select form-select-sm text-uppercase" name='opensubscriptions' required>
<option value="NO" <?= set_select('opensubscriptions','NO')?>>NO</option>
<option value="SI" <?= set_select('opensubscriptions','SI')?>>SI</option>
</select>
</div>
This works well if there is a validation error. But i need, when i load the form to edit it, that the dropdown shows the value that was stored on the database.
If for instance on the database i have the value SI, it shows NO. How can i change the code so when i load the form to edit the record, the correct value is selected in the dropdown?