thinkphp Automated validation failure Solutions _php Tips

Source: Internet
Author: User
Copy Code code as follows:

/*
* Landing
*/
Public Function Login () {
if ($_post[' submit ']) {
$DB = D (' Login ');//Custom model processing
If inside is the automatic verification of the thinkphp.
if (! $DB->create ()) {
$this->redirect (' Index/login ', ', 3, ' Error message: '. $DB->geterror (). ' <br/> system will return in 3 seconds after landing ... ');
}else{
$con [' LoginName '] = $_post[' username '];
$con [' loginpwd '] = MD5 ($_post[' userpwd ']);
$list = $DB->where ($con)->find ();
if (count ($list) >0) {
echo ' OK ';
}else{
$this->redirect (' Index/login ', ', ', 3, ' Error message: Username or password error <br/> system will return in 3 seconds after landing ... ');
}
}
return;
}
This just encapsulates the address of the template file.
A (' Public ')->showpage (' login ');
}

Copy Code code as follows:

<?php
Class Loginmodel extends Model {
//Set datasheet
Protected $tableName = ' admin ';
//Auto-Verify settings
Protected $_validate = Array (
Array (' username ', ' require ', ' username must be!) ', 1,
Array (' userpwd ', ' require ', ' password must! ', 1),
);
/* AutoFill If it is not automatically validated, uncomment this code to see.
Protected $_auto = Array (
Array (' status ', ' 1 ', self::model_insert),
Array (' Create_time ', ' time ', Self:: Model_insert, ' function '),
);/
/* Reference ThinkPHP2.0 Development Manual: thinkphp manual type checking is only for database-level validation, Therefore, the system also has built-in data object's automatic verification function to complete the model's business rule verification, and in most cases, the data object is created by the $_post data submitted by the form. You need to use the automatic verification function of the system, just define the $_validate property in the Model class
/
/* It says here, just define the $_validate attribute in the model class, but when using ThinkPHP2.1, Does not pass validation, $DB->geterror () returned without error, and $db->geterror () returns "token form error"
/
}
?>
when refreshed

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.