0
我的驗證工作得很好,但看似隨機,retured值不是我的模型集驗證錯誤,沒有什麼應該觸發錯誤,但一個「 1" 或‘2’則返回..CakePHP驗證()怪數組返回(1,2)值行爲
即使所有的字段數據是有效的,我有時會在我的陣列得到一個返回值‘1’或‘2’......
這裏是我的驗證在我的控制器:
if ($this->RequestHandler->isAjax()) {
if ($this->Plan->validates()) {
$this->Plan->set($this->data);
$errors = $this->Plan->invalidFields();
$this->set('errors', $errors);
} else {
$this->Plan->set($this->data);
}
}
這裏是我的模型驗證:
'ApplicantAge' => array(
array('rule'=> array('maxLength', 3),
'message' => 'Applicant Age cannot be longer than 3 digits.'),
'last' => true,
array('rule' => array('range', -1, 120),
'message' => 'Applicant Age cannot exceed 120.'),
'last' => true,
array('rule' => 'numeric',
'message' => 'Applicant Age must be a valid age.'),
'last' => true,
),
'SpouseAge' => array(
array('allowEmpty' => true),
'last' => true,
array('rule' => array('maxLength', 3),
'message' => 'Spouse Age cannot be longer than 3 digits.'),
'last' => true,
array('rule' => array('range', -1, 120),
'message' => 'Spouse Age cannot exceed 120.'),
'last' => true,
array('rule' => 'numeric',
'message' => 'Spouse Age must be numeric.'),
'last' => true,
),
'NumberChildren' => array(
array('allowEmpty' => true),
'last' => true,
array('rule' => array('range', -1, 20),
'message' => 'Number of Children cannot exceed 20.'),
'last' => true,
array('rule' => 'numeric',
'message' => 'Number of Children must be numeric.'),
'last' => true,
),
'ZipCode' => array(
array('rule' => array('postal', null, 'us'),
'message' => 'Zip Code format must be valid. Example: 97756'),
'last' => true,
array('rule' => array('minLength', 5),
'rule' => array('maxLength', 5),
'message' => 'Zip Code must be 5 digits.'),
'last' => true
),