简体   繁体   中英

How to set_value On Dropdown Form Codeigniter

I Have this form,but whenever the form_validation return FALSE. The Dropdown form always set to default which was PLEASE SELECT.

How do i Set the value like the input form,i dont know where to put the set_value

Dropdown Form:

<div class="form-group">
     <select class="form-control form-control-sm" id="exampleFormControlSelect1" name="jenisKelamin">
        <option value="">PLEASE SELECT</option>
           <?php foreach ($system as $d) : ?>
              <?php if ($d->system_type=="JENIS_KELAMIN"): ?>
            <option value="<?= $d->system_value_txt ?>"><?= $d->system_value_txt ?></option>
              <?php endif ?>
            <?php endforeach; ?>
      </select>
      <small class="text-danger"><?= form_error('jenisKelamin') ?></small>
</div>

To set a default dropdown menu, you could use the set_select() method on your option input like this :

<div class="form-group">
     <select class="form-control form-control-sm" id="exampleFormControlSelect1" name="jenisKelamin">
        <option value="">PLEASE SELECT</option>
           <?php foreach ($system as $d) : ?>
              <?php if ($d->system_type=="JENIS_KELAMIN"): ?>
                <option value="<?= $d->system_value_txt ?>" <?php echo set_select('jenisKelamin', $d->system_value_txt); ?> ><?= $d->system_value_txt ?></option>
              <?php endif ?>
            <?php endforeach; ?>
      </select>
      <small class="text-danger"><?= form_error('jenisKelamin') ?></small>
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM