How to use form validation library in codeigniter

Form validation is required in all the form wherever you get inputs from user. Server side validation is more secure than client side validation, because user could disable javascript by blocking javascript from browser.

You can define validation using form validation library in codeigniter.

I am going to explain you how to use form validation library in codeigniter.In this tutorial my app name is myapp

1.) First of all you need to load form helper and form_validation library inside routes.php .see below.

$autoload[‘libraries’] = array(‘database’,’form_validation’);
$autoload[‘helper’] = array(‘url’,’html’,’file’,’form’);

2.) Next, Create a view by running below script.

font-family: Verdana;
font-size: 18pt;
font-style: normal;
font-weight: bold;
text-align: center;
font-family: Verdana;
font-size: 12pt;
font-style: normal;
font-weight: bold;
border-collapse: collapse;
font-size: 11px;
<?php echo form_open('register',array('name'=>'registerview')); ?>
<table align="center" cellpadding = "5">
<td><input type="text" size="40px" name="name" /></td>
<td class="error"><?php echo form_error('name'); ?></td>
<td><input type="text" size="40px" name="mobile" maxlength="10"/></td>
<td class="error"><?php echo form_error('mobile'); ?></td>
<td><input type="text" size="40px" name="address" maxlength="100"/></td>
<td class="error"><?php echo form_error('address'); ?></td>
<td colspan="5" align="center">
<input type="submit" value="Register"/></td>
<?php echo form_close();?>

3.) Now create a controller and all form validation process should goes here as i am showing below.

defined('BASEPATH') OR exit('No direct script access allowed');

class RegisterController extends CI_Controller {
public function index()
public function register()  {
if($this->form_validation->run() == false){
$data = array(

4.) After done above now go to browser and type http:\\localhost\myapp and try to submit your form without any input.You will get below screen.

Form validation using codeigniter library
Thank you for reading this post. we hope you like this Post, Please feel free to comment below, your suggestion and problems if you face – let us know. We’d love to help!


I am Hitesh from Jamshedpur (India). I have been working as a Web Application Developer from last 4+ years. I love diverse and attention catching web presence for a variety of users. Also I love to learn new things in Web Development.

error: Content is protected !!
Secured By miniOrange