Dropdown Population
I am trying to populate my dynamic dropdown menu using CI:
My issue is that when I set my dropdown value and text ($formImageCaptionDropDown = array($get_images['id'] => $get_images['description']);
) it does not display - just displays a blank dropdown box.
I have done print_r
on my $get_images
so I know that this is working correct.
I also know that I am to use $var['value']
because I have copied the format of another page that uses the images model and is working fine.
I just cannot seem to populate the dropdown menu
I have the following code:
<?php
//Setting form attributes
$get_images = $this->image_model->getImages();
$formImageCaption = array('id' => 'imageCaption', 'name' => 'imageCaption');
$formImageCaptionDropDown = array($get_images['id'] => $get_images['description']);
$formImageCaptionSelection = array开发者_JAVA百科('id' => 'captionSelection', 'name' => 'captionSelection');
$formSubmit = array('id' => 'submit','name' => 'submit','value' => 'Edit Caption');
?>
<div id ="formLayout">
<?php echo form_open('admin/imagecaption',$formImageCaption);
echo form_fieldset();
?>
<p>Please Select A Caption Below To Edit: </p>
<?php echo form_label ('Caption:', 'caption');?>
<?php echo form_dropdown('caption', $formImageCaptionDropDown); ?>
<div id="errorCaption"><?php echo form_error('caption');?></div>
<span class="small">Required Field</span>
<?php echo form_fieldset_close();
echo form_close(); ?>
</div>
I have resolved my issue by doing the following:
I moved the line
$get_images = $this->image_model->getImages();
into my controller as$data['$get_images'] = $this->image_model->getImages();
In my view I did the following:
<?php foreach ($get_images as $image){
echo '<option value="'.$image['id'].'">'.$image['description'].'</option>';
};
?>`
精彩评论