Skip to Content
PHPCODE
CodeIgniter Login Form Validation
codeigniter code / July 28, 2018

Login Form Validation in codeigniter

Step 1: Created Controller login.php and function created admin_login

For Example
login.php
<?php
class Login extends MY_Controller
{
public function index()
{
$this->load->helper(‘form’);
$this->load->view(‘public/admin_login’);
}
public function admin_login()
{
$this->load->library(‘form_validation’);
$this->form_validation->set_rules(‘username’,’User Name’,’required|trim|alpha’);
$this->form_validation->set_rules(‘password’,’Password’,’required’);
$this->form_validation->set_error_delimiters(“<p class=’text-danger’>”,”</p>”);
if($this->form_validation->run()==TRUE)
{
echo “validation success”;
}
else
{
$this->load->view(‘public/admin_login’);
//echo validation_errors();
}
}
}
?>

Step 1: Created view admin_login.php
<?php include(‘public_header.php’);?>
<div class=”container”>
<?php echo form_open(‘login/admin_login’);?>
<fieldset>
<legend>Admin Login</legend>
<div class=”row”>
<div class=”col-lg-12″>
<?php echo form_label(‘User Name’);?>
</div>
</div>
<div class=”row”>
<div class=”col-lg-6″>
<div class=”form-group”>
<?php
echo form_input([‘class’=>’form-control’,’name’=>’username’,’placeholder’=>’User Name’]);
?>
</div>
</div>
<div class=”col-lg-6″>
<?php echo form_error(‘username’);?>
</div>
</div>
<div class=”row”>
<div class=”col-lg-12″>
<?php echo form_label(‘Password’);?>
</div>
</div>
<div class=”row”>
<div class=”col-lg-6″>
<div class=”form-group”>
<?php
echo form_password([‘class’=>’form-control’,’name’=>’password’,’placeholder’=>’Password’]);
?>
</div>
</div>
<div class=”col-lg-6″>
<?php echo form_error(‘password’);?>
</div>
</div>
<?php
echo form_submit([‘class’=>’btn btn-primary’,’value’=>’LOGIN’]),
form_reset([‘class’=>’btn btn-default’,’value’=>’RESET’]);
?>
</fieldset>
<?php echo form_close();?>
</div>

<?php include(‘public_footer.php’);?>

PHPCODE © 2024