Home > Backend Development > PHP Tutorial > Detailed explanation of CodeIgniter form verification method examples, codeigniter form_PHP tutorial

Detailed explanation of CodeIgniter form verification method examples, codeigniter form_PHP tutorial

WBOY
Release: 2016-07-12 08:57:52
Original
747 people have browsed it

Detailed explanation of CodeIgniter form verification method examples, codeigniter form

This article describes the CodeIgniter form verification method through examples. Share it with everyone for your reference, the details are as follows:

1. Write a view file myform.php in the D:CodeIgnitersystemapplicationviews directory

<html>
<head>
<title>My Form</title>
</head>
<body>
<&#63;php echo $this->validation->error_string;&#63;>
<&#63;php echo form_open('form/index');&#63;>
<h5>Username</h5>
<input type="text" name="username" value="" size="50" />
<h5>Password</h5>
<input type="text" name="password" value="" size="50" />
<h5>Password Confirm</h5>
<input type="text" name="passconf" value="" size="50" />
<h5>Email Address</h5>
<input type="text" name="email" value="" size="50" />
<div><input type="submit" value="Submit" /></div>
</form>
</body>
</html>

Copy after login

Then write a view file formsuccess.php

<html>
<head>
<title>My Form</title>
</head>
<body>
<h3>Your form was successfully submitted!</h3>
<p><&#63;=anchor('form', 'Try it again!'); &#63;></p>
</body>
</html>

Copy after login

2. Write a controller file form.php in the D:CodeIgnitersystemapplicationcontrollers directory

<&#63;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');
   }
 }
}
&#63;>

Copy after login

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

Ok, the results are out

Readers who are interested in more PHP-related content can check out the special topics of this site: "Introduction to codeigniter tutorial", "CI (CodeIgniter) framework advanced tutorial", "php date and time usage summary", "php object-oriented program" Design introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"

I hope this article will be helpful to everyone in PHP programming.

Articles you may be interested in:

  • Codeigniter’s method of detecting form post data
  • Codeigniter implements URL jump after user login verification
  • CodeIgniter Configuration autoload.php automatic loading usage analysis
  • CodeIgniter controller business logic example analysis
  • CodeIgniter custom controller MY_Controller usage analysis
  • CodeIgniter hook usage example detailed explanation
  • CodeIgniter configuration database.php usage example analysis
  • CodeIgniter multi-language implementation method detailed explanation
  • CI (CodeIgniter) model usage example analysis
  • CodeIgniter assisted third party Class library third_party usage analysis
  • Detailed explanation of CodeIgniter extended core class instance
  • Notes on using CodeIgniter view
  • Detailed explanation of CodeIgniter read-write separation implementation method

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1106128.htmlTechArticleDetailed explanation of CodeIgniter form verification method examples, codeigniter form This article describes the CodeIgniter form verification method through examples. Share it with everyone for your reference, the details are as follows: 1. In D:CodeIgni...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template