Phptp verification form and auto-Fill function code. For more information, see
Php tp verification form and auto-Fill function code. For more information, see
The Code is as follows:
Class FormModel extends Model {
// Automatic Verification settings
/*
* 1. Automatic Verification
Automatic Verification is defined as follows: array (field, rule, message, condition, type, when, params)
Field: indicates the field name of the database;
Rule: indicates a rule;
The value depends on the type;
If condition is function (callback), rule is a function name.
Condition is in, and rule is an array
Message: indicates a message prompt;
Condition: indicates a verification condition.
Its value:
Self: MUST_VALIDATE indicates that 1 must be verified.
Self: VALUE_VAILIDATE indicates verification 2 when not empty
Self: EXISTS_VAILIDATE indicates that fields in the form are verified (default). 0
Type: indicates the verification type.
Its value:
Function (callback) indicates that the function in a Model is called.
Confirm indicates verifying whether the two fields are the same
Whether in is within the range of an array
Equal verify whether it is equal to a value
Unique verifies that a value is unique
Regex uses regular expressions (default)
When: Indicates whether verification is required.
Its value:
Self: INSERT_STATUS verification during the add operation
Self: verified during the UPDATE_STATUS update operation
Self: ALL_STATUS (needless to say)
Params: parameter (I am not sure about the specific information)
**/
Protected $ _ validate = array (
Array ('title', 'require ', 'The title is required! ', 1), // must be verified
Array ('email ', 'email', 'mailbox format error! ', 2), // verification when not empty
Array ('content', 'require ', 'content required '),
Array ('title', '', 'title already exists ', 0, 'unique', self: MODEL_INSERT ),
);
// Automatic Filling settings
// Array (fill field, fill content, fill condition, additional rules)
/* Fill conditions include:
Processing when adding new data (default mode) self: filling when MODEL_INSERT ADD operation
When updating data, process the self: MODEL_UPDATE udate operation.
ALL is processed in ALL cases. self: MODEL_BOTH (needless to say)
Additional rules include:
Function usage function
Callback Method
Fill field with other fields
String (default)
*/
Protected $ _ auto = array (
Array ('status', '1', self: MODEL_INSERT ),
Array ('create _ time', 'time', self: MODEL_INSERT, 'function '),
);
}
?>