In this article, We will learn how to validate a form in Codeigniter 3. Load the URL and form helper with the form_validation library, then validate the form.

use the following steps to validate the form:

Step 1: Make HTML Form

create a view and put the following code to make form.



        <title>My Form</title> 

        <form action = "<?php echo base_url(); ?>Home/save" method = "post">
            <?php echo validation_errors(); ?>  
            <h5>Form validation</h5> 
            <input type = "text" name ="name" value ="" placeholder="Name"/><br><br>  
            <input type = "text" name ="email" value ="" placeholder="Email"/><br>  <br>
            <div><input type = "submit" value = "Submit" /></div>  


Step 2: Make Controller

make controller to get the html form data from view



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

class Home extends CI_Controller {

    public function __construct() {
        $this->load->helper(array('form', 'url'));

    public function index() {


    public function save() {
        $this->form_validation->set_rules('name', 'Name', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
        if ($this->form_validation->run() == FALSE) {
        } else {
            //if form successfully validated 
            //store data in db


I hope it will work for you ...........

Are you facing problems in understanding this article?
You can watch the video. Watch it now