Skip to content
  • Github
  • Facebook
  • twitter
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
CodeIgniter Form Validation Example

Codeigniter Form Validation Example

Posted on June 11, 2018December 17, 2022 By XpertPhp 1 Comment on Codeigniter Form Validation Example

In this article, we will explain to you about CodeIgniter form validation example. Listen as we talk you through CodeIgniter form validation with examples and even a demonstration of how to build it if needed.

Today we are going to learn more about how to create server-side form validation using the CodeIgniter framework. Whenever creating Codeigniter validation at that time load “form_validation” and “session” library and also load helpers such as form, URL, and HTML.

if the user fills all form data then click on button and form_validation is true then data will be inserted into database otherwise given the error message.

See below code.

Create controller and put below method

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public function add()
{
    $this->load->library(array('form_validation','session'));
    $this->load->helper(array('url','html','form'));
if($this->input->post('btnadd'))
{
  $this->form_validation->set_rules('txtCategoryName', 'Category Name', 'trim|required');
 
            if ($this->form_validation->run() == TRUE)
            {
$arrData['first_name'] = $this->input->post('txtFname');
$arrData['last_name'] = $this->input->post('txtLname');
$arrData['address'] = $this->input->post('txtAddress');
$arrData['email'] = $this->input->post('txtEmail');
$arrData['mobile'] = $this->input->post('txtMobile');
 
$insert= $this->register_model->insert($arrData);
if($insert)
{
redirect('register');
}
    }
}  
$this->load->view('register/add');
}

Create view file of add.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<form method="post" name="frmAdd">
        <table align="center">
            <tr>
                <td colspan="2" align="center">Add Record</td>
            </tr>
 
            <tr>
                <td>First Name</td>
                <td>
   <input type="text" name="txtFname">
                   <span class="input_error"><?php echo form_error('txtFname'); ?></span>  
        </td>
            </tr>
            <tr>
                <td>Last Name</td>
                <td>
  <input type="text" name="txtLname">
  <span class="input_error"><?php echo form_error('txtLname'); ?></span>
</td>
            </tr>
            <tr>
                <td>Address</td>
                <td><textarea name="txtAddress" rows="4" cols="16"></textarea> </td>
            </tr>
            <tr>
                <td>Email</td>
                <td>
  <input type="text" name="txtEmail">
  <span class="input_error"><?php echo form_error('txtEmail'); ?></span>
</td>
            </tr>
            <tr>
                <td>Mobile</td>
                <td>
  <input type="text" name="txtMobile">
  <span class="input_error"><?php echo form_error('txtMobile'); ?></span>  
       </td>
            </tr>
            <tr>
                <td colspan="2" align="center"><input type="submit" value="Add" name="btnadd"> </td>
            </tr>
        </table>
</form>
See also  Generate a PDF file using Dompdf in Codeigniter

Codeigniter Tags:CodeIgniter Form Validation, codeigniter tutorial, form validation, validation

Post navigation

Previous Post: jQuery Remove All Space From String
Next Post: Login logout and register example in Codeigniter

Latest Posts

  • Laravel 12 Ajax CRUD Example
  • Laravel 12 CRUD Example Tutorial
  • How to Create Dummy Data in Laravel 11
  • Laravel 11 Yajra Datatables Example
  • Laravel 11 Ajax CRUD Example
  • Laravel 11 CRUD Example Tutorial
  • Laravel 10 Ajax CRUD Example Tutorial
  • Laravel 10 CRUD Example Tutorial
  • How to disable button in React js
  • JavaScript Interview Questions and Answers

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Interview
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch laravel social login learn jquery nodejs pagination payment gateway php with mysql react js example react js tutorial send mail validation wysiwyg editor wysiwyg html editor

Copyright © 2018 - 2025,

All Rights Reserved Powered by XpertPhp.com