开发者

codeigniter form drop down add edit with set value

开发者 https://www.devze.com 2023-03-19 20:04 出处:网络
I\'m trying to use one form to perform add and edit functions. I\'m currently saving officer\'s id (retrieving officers name and id from officer table) and saving the id in开发者_StackOverflowto an \'

I'm trying to use one form to perform add and edit functions. I'm currently saving officer's id (retrieving officers name and id from officer table) and saving the id in开发者_StackOverflowto an 'admin' table along with other information.

Adding a new record works fine but I am not able to retrieve the saved details to be able to edit the officer's details using drop down.

In the controller I have the following code that stores officer's details from 'officer' table into an array

<?php $data['OfficersToDisplay'] = $this->officers_model->Officers(TRUE);?>

In the view I have the code below that outputs officer's name:

<?php  $idOfficer = @field($this->validation->idOfficer, $item->idOfficer);  ?>
<tr>
<td><label>Officer</label></td>
<td>
<?php echo form_dropdown('idOfficer', $OfficersToDisplay, set_value('idOfficer'));?>
 <span> <?php echo form_error('idOfficer'); ?> </span>
</td>
</tr>

It will be great if someone can let me know what code needs to be added/updated so that current(saved) officer's details is added to the drop down box along with other ones.


You might want to check the userguide from CI: http://codeigniter.com/user_guide/helpers/form_helper.html

A good example is shown there how to use the form_dropdown function.

0

精彩评论

暂无评论...
验证码 换一张
取 消