PHP codeigniter form validation Example

PHP codeigniter form validation Example

Today, We want to share with you PHP codeigniter form validation Example.
In this post we will show you Simple codeigniter form validation example using PHP, hear for Learn Php CodeIgniter Form Validation With Example
we will give you demo and example for implement.
In this post, we will learn about CodeIgniter Form Validation with an example.

Form Validation

CodeIgniter Server side validation(PHP) is most of the secure way than Browser side/client side validation, so (Browser side) client side validation can be bypass(insecure) through script manipulation tools and skiping.

Validation is ont type of most an important process while secure data building web application.
It means that the information-data that we are getting(true) is proper and valid(true data) to store database or process.
CodeIgniter Form Validation has made this task very easy and.

CodeIgniter Form Validation listing of all the rules with their specification info.

CodeIgniter List of Validation Rule

1)required // input tag Returns boolean (true or false) FALSE if the HTML form field is empty.

2)matches // input tag Returns boolean (true or false) FALSE if the HTML form field does not match the defined value of all parameter (html parameter).

3)is_unique // input tag Returns boolean (true or false) FALSE if the HTML form field is not unique to the table and field name in the all parameter (html parameter).

4)min_length // input tag Returns boolean (true or false) FALSE if the HTML form field is shorter than the all parameter (html parameter) value.

5)max_length // input tag Returns boolean (true or false) FALSE if the HTML form field is longer than the all parameter (html parameter) value.

6)exact_length // input tag Returns boolean (true or false) FALSE if the HTML form field is not exactly the all parameter (html parameter) value.

7)greater_than // input tag Returns boolean (true or false) FALSE if the HTML form field is less than the all parameter (html parameter) value or not numeric.

8)less_than // input tag Returns boolean (true or false) FALSE if the HTML form field is greater than the all parameter (html parameter) value or not numeric.

9)alpha // input tag Returns boolean (true or false) FALSE if the HTML form field contains anything other than alphabetical characters.

10)alpha_numeric // input tag Returns boolean (true or false) FALSE if the HTML form field contains anything other than alpha-numeric characters.

11)alpha_dash // input tag Returns boolean (true or false) FALSE if the field contains anything other than alpha-numeric characters, underscores or dashes.

12)numeric // input tag Returns boolean (true or false) FALSE if the HTML form field contains anything other than numeric characters.

13)integer // input tag Returns boolean (true or false) FALSE if the HTML form field contains anything other than an integer.

14)decimal // input tag Returns boolean (true or false) FALSE if the HTML form field contains anything other than a decimal number.

15)is_natural // input tag Returns boolean (true or false) FALSE if the HTML form field contains anything other than a natural number.

16)is_natural_no_zero // input tag Returns boolean (true or false) FALSE if the HTML form field contains anything other than a natural number, but not zero.

17)valid_email // input tag Returns boolean (true or false) FALSE if the HTML form field does not contain a true – valid info email address.

18)valid_emails // input tag Returns boolean (true or false) FALSE if any value provided in a comma separated list is not a true – valid info email.

19)valid_ip // input tag Returns boolean (true or false) FALSE if the supplied IP is not true – valid info.

20)valid_base64 // input tag Returns boolean (true or false) FALSE if the supplied string contains anything other than true – valid info Base64 characters.

Example : codeigniter form validation

Create a view file mycodeigniform.php and save the below code it in application/views/myform.php. This web page shall display ci-form where user can submit his user name and we will validate this page to ensure that it should not be empty while submitting.

mycodeigniform.php



 
    
      My Form - codeigniter with validation 
   
	
   
      
Write your userName

IN codeigniter,Create a view file myformsuccesspage.php and save it in this file : in application/views/myformsuccesspage.php.
This view page will be displayed if the codeigniter-form is validated successfully or not check.

myformsuccesspage.php



 
    
      My Form : codeigniter form validation using php 
    
	
     
      

Your codeigniter form was successfully submitted! Good luck..!

codeigniter Create a controller file codeigniform.php and save it.in file: in application/controller/codeigniform.php. This CI-form will either, show errors/display errors if it is not / validated form properly or redirected to myformsuccesspage.php page.

codeigniform.php

$this->load->library(‘form_validation’);

/* codeigniter Set validation all rule for user_name input field in the form used */
$this->form_validation->set_rules(‘user_name’, ‘user_name’, ‘required’);

if ($this->form_validation->run() == FALSE) { //check condition
$this->load->view(‘myform’);
}
else {
$this->load->view(‘myformsuccesspage’);
}
}
}
?&>

route Add the create following line in this file: application/config/routes.php.

routes.php


$route['validation'] = 'Form';

Now Go to execute this file and example by visiting the following URL in the browser (Mozila,chrome.).

This URL(or localhost) may be different based on your site Like Pakainfo.com.

 https://www.pakainfo.com/index.php/validation

Leave a Comment