thinkphp Form Auto-validation example, thinkphp example _php tutorial

Source: Internet
Author: User

thinkphp Form Auto-validation example, thinkphp example


Using the TP 3.2 framework

Public Function Add_post () {///Validation Rule $rule=array (Array (' name ', ' Require ', ' Please enter name ', 1),//must verify name), $m =m (' user ');//Get Name , sex,contact data to the model and verify if (! $m->field (' name,sex,contact ')->validate ($rule)->create ()) $this->error ($m- >geterror ()); $result = $m->add (); if (! $result) $this->error (' Add failed '), $this->success (' Add Success ', U (' dir '));}

Validation rules can also be written into the model, but I feel a little trouble, one is sometimes different page verification method will not be the same, the second is to see the code in this Add_post event, it is clear what data to receive, how to verify that the data can have a general understanding at the first glance, so summed up this way.


thinkphp form validation is not Ajax? Is there a better form validation tool than thinkphp? Like jquery form.

Thinkphp's background framework, which itself does not have Ajax. Using jquery form to submit is good, very convenient. You can take a look at the official thinkphp example
Www.thinkphp.cn/extend/230.html

thinkphp Auto-validation issues

show you an example I wrote:
//form validation
Protected $_validate=array (
//array (' Validation field ', ' Validation rule ', ' Error prompt ', validation criteria, additional rules , authentication time)
Array (' uname ', ' require ', ' username must be verified! ', 1, ' Regex ', 3),
//array (' username ', ', ' username already exists ', 1, ' unique ', 1),
Array (' pwd ', ' require ', ' password must be filled in! '),

Array (' pwd ', ' checkpwd ', ' password length not less than 6 bits ', 1, ' callback '),
);

Function Checkpwd () {
$password =$_post[' pwd '];
if (strlen ($password) >=6) {
return true;
} else {
return false;
}
}
//form Map
Protected $_map=array (
' uname ' = ' username ',
' pwd ' = ' password ',
);
AutoComplete
Protected $_auto=array (
//array (fill field, fill content, fill condition, additional rule) fill condition: 1, insert 2, update 3, all
Array (' reg_date ', ' GetDate ', 1, ' callback '),
Array (' Password ', ' MD5 ', 3, ' function '),
);
function GetDate () {
return date (' y-m-d h:i:s ');
}
 

http://www.bkjia.com/PHPjc/893423.html www.bkjia.com true http://www.bkjia.com/PHPjc/893423.html techarticle thinkphp form Automatic validation using the example, the thinkphp example uses the TP 3.2 Framework public Function Add_post () {//Validation rule $rule=array (Array (' name ', ' Require ', ' Please enter the name ', 1),//Must be inspected ...

  • Related Article

    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.