(05-13-2024, 11:38 AM)kcs Wrote: Hi,
I am not managing to make the set_select work on a form.
I am following the documentation, I call my form using form_open inside my view:
PHP Code:
<?= form_open('admin/bookings/update/'.$booking->id, 'id="formBookings"') ?>
<?= $this->include('/admin/bookings/form_fields'); ?>
<button class="submit">Update</button>
Inside the form, here's a select:
PHP Code:
<label>Status <?= $booking->status; ?></label>
<select name="status" id="status">
<option>Select</option>
<option value="pending" <?= set_select('status', $booking->status) ?>>Pending</option>
<option value="option" <?= set_select('status', $booking->status) ?>>Option</option>
<option value="confirmed" <?= set_select('status', $booking->status) ?>>Confirmed</option>
</select>
I added the booking status inside the label for testing, so I can see that it returns a value. But which ever value is returned, the select does not take it, it always shows 'select'.
What am I doing wrong?
So, Why don't you just use :
PHP Code:
<option value="pending" <?php if($booking->status == "pending"){echo 'selected';} ?>>Pending</option>
By the way, keep your status as tiny_int in your database instead of varchar.
0 = pending
1 = option
2 = confirmed
etc
Additionally, in your method be careful with double semicolon
Code:
->first();; and try to place "where" after "join"s.