![]() |
Hello,
I'm building form where user can submit some inputs. I check for validation errors and re display the form with error messages and also i use <?=old('filed_name')?> to display old entered data. Everything works for input box but, i have dropdown box where user cans select gender, But how we can show the old data on this dropdown. My code (Textbox) : Code: <input type="text" name="first_name" value="<?=old('first_name')?>" id="firstName"> My code (Dropdown) : PHP Code: <select id="defaultSelect" value="<?= old('gender') ?>" name="gender" class="form-select"> But this dropdown not working with old selected values.
You will need to use the set_select() form helper. See docs
PS: If you are using any of the form_open() helpers (form_open, form_open_multipart), you do not need to use old(). Use set_value() instead. (09-04-2023, 11:27 PM)sammyskills Wrote: You will need to use the set_select() form helper. See docs Thanks. I'm using form helper but i tried this , but not working PHP Code: <select id="defaultSelect" name="nationality_id" class="form-select">
You need to add the value to check for after the field name, like so:
PHP Code: <option name="<?= $nation['id'] ?>" <?= set_select('nationaility_id', $nation['id']) ?>><?= $nation['name'] ?></option> |
Welcome Guest, Not a member yet? Register Sign In |