Skip to Content
PHPCODE
CodeIgniter Populate Edit Form
codeigniter code / August 2, 2018

Populate Edit Form in Codeignter

step 1:- Created edit.article.php in view

<?php include_once(‘admin_header.php’); ?>
<?php echo form_open(‘admin/update_article’);?>
<div class=”container”>
<fieldset>
<legend>Edit Article</legend>
<div class=”row”>
<div class=”col-lg-12″>
<?php echo form_label(‘Article Title’);?>
</div>
</div>
<div class=”row”>
<div class=”col-lg-6″>
<div class=”form-group”>
<?php
echo form_input([‘class’=>’form-control’,’name’=>’title’,’placeholder’=>’Article Title’,’value’=>set_value(‘title’,$article->title)]);
?>
</div>
</div>
<div class=”col-lg-6″>
<?php echo form_error(‘title’);?>
</div>
</div>
<div class=”row”>
<div class=”col-lg-12″>
<?php echo form_label(‘Article Body’);?>
</div>
</div>
<div class=”row”>
<div class=”col-lg-6″>
<div class=”form-group”>
<?php
echo form_textarea([‘class’=>’form-control’,’name’=>’body’,’placeholder’=>’Article Body’,’value’=>set_value(‘body’,$article->body)]);
?>
</div>
</div>
<div class=”col-lg-6″>
<?php echo form_error(‘body’);?>
</div>
</div>
<?php
echo form_submit([‘class’=>’btn btn-primary’,’value’=>’SUBMIT’]),
form_reset([‘class’=>’btn btn-default’,’value’=>’RESET’]);
?>
</fieldset>
<?php echo form_close();?>
</div>
<?php include_once(‘admin_footer.php’);?>

step 2 :- created controller function

public function edit_article($article_id)
{
$this->load->helper(‘form’);
$this->load->model(‘articlesmodel’,’articles’);
$article=$this->articles->find_article($article_id);
$this->load->view(‘admin/edit_article’,[‘article’=>$article]);
}

PHPCODE © 2023