Welcome Guest, Not a member yet? Register   Sign In
how to use set_select on a form to show the old value?
#10

(This post was last modified: 05-14-2024, 07:48 AM by demyr.)

(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.
Reply


Messages In This Thread
RE: how to use set_select on a form to show the old value? - by demyr - 05-14-2024, 07:46 AM



Theme © iAndrew 2016 - Forum software by © MyBB