I have to set/display the value in form fields during form_validation in codeIgniter but data is not set/displaying by using set_value function.
Here is my code,
view page -
login_form.php
<?= form_open('admin/login');?>
<?= form_label('Username','username'); ?>
<?= form_input(['id'=>"username", 'placeholder'=>"Username", "name"=>"username", 'value'=>set_value('username')]); ?><br>
<?= form_error('username'); ?>
<br>
<?= form_label('Password', 'Password'); ?>
<?= form_password(["id"=>"password", "placeholder"=>"Password",
"name"=>"pass", "value"=>set_value('pass')]); ?>
<?= form_error('pass') ?>
<br>
<?php echo form_submit(['value'=>'Login']); ?>
<?= form_close(); ?>
Controller -
admin.php
public function login(){
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'User Name', 'required|alpha|trim');
$this->form_validation->set_rules('pass', 'Password', 'required');
if($this->form_validation->run()):
echo "Validation Success";
else:
$this->load->view('login_form']);
endif;
}
Please help and give suggestion regarding this.