CodeIgniter Form Verification Method Example detailed _php instance

Source: Internet
Author: User
Tags getting started with php php database codeigniter

This example describes the CodeIgniter form validation method. Share to everyone for your reference, specific as follows:

1. Write a view file under the D:\CodeIgniter\system\application\views directory myform.php


 
 

2. Write a controller file under the D:\CodeIgniter\system\application\controllers directory form.php

<?php
class Form extends controller{
 function index () {
 $this->load->helper array (' Form ', ' url ' ));
 $this->load->library (' validation ');
   $rules [' username '] = "required";
    $rules [' password '] = "required";
    $rules [' passconf '] = "required";
    $rules [' email '] = "required";
    $this->validation->set_rules ($rules);    $this->validation->set_error_delimiters (' <div class= ' error ' > ', ' </div> ');
 $fields [' username '] = ' username ';
 $fields [' password '] = ' password ';
 $fields [' passconf '] = ' Password confirmation ';
 $fields [' email '] = ' email address ';
 $this->validation->set_fields ($fields);
   if ($this->validation->run () ==false) {
   $this->load->view (' myview/myform ');
   } else {
   $this->load->view (' myview/formsuccess.php ');
   }
 }
? >

3.http://localhost:8888/index.php/form/index visit

Okay, the results are out.

More interested in PHP related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP date and Time usage summary", "PHP object-oriented Program Design Primer", "PHP string ( String) Usage summary, "Getting Started with Php+mysql database operations" and "Summary of common PHP database Operations Tips"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.