cili
cili

Reputation: 1067

Codeigniter: repopulate dropdowns array using set_value

I have this piece of code:

<?php for ( $i=1; $i<=9; $i++ ) : ?>
  <select name="codes[]">
    <?php foreach ( $errors as $error ) : ?>
    <option value="<?=$error->code?>" <?=set_select( 'codes', $error->code )?>><?=$error->fault?></option>
    <?php endforeach; ?>
  </select>
<?php endfor; ?>

The set_select part doesn't seem to work well, even though I added the validation rule in my controller:

$this->form_validation->set_rules( 'codes', '', '' );

After submitting the form, all dropdowns get the last dropdown's selected value.

Any idea how I could fix this? The user guide doesn't give details about this specific situation.

Thank you.

Upvotes: 1

Views: 454

Answers (1)

Rick Calder
Rick Calder

Reputation: 18685

Sorry exhausted, I didn't see you set the rule, try giving it a real rule and see if that works. Since it will always have a value this should work fine.

$this->form_validation->set_rules('codes','codes','trim|required');

Upvotes: 1

Related Questions