0
我有一個模型,具體如下驗證規則衝突的警予模型場景
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
//post of step 1
if (isset($_POST['yt0']))
{
return array(
array('EmailAddress,', 'required','message' => Yii::t('message', 'USERNAME_REQUIRED')),
array('Password,', 'required','message' => Yii::t('message', 'PASSWORD_REQUIRED')),
array('confirmPassword,', 'required','message' => Yii::t('message', 'CONFIRM_PASSWORD_REQUIRED')),
array('Password','length', 'max' => 100, 'min' => 6, 'tooShort' => Yii::t('message', 'PASSWORD_LENGTH')),
array('confirmPassword', 'compare', 'compareAttribute'=>'Password','message' => Yii::t('message', 'PASSWORD_COMPARE')),
array('EmailId,', 'required','message' => Yii::t('message', 'EMAILID_REQUIRED')),
array('EmailId','email','message'=>Yii::t('message', 'EMAILID_VALID')),
array('chapterCode,', 'required','message' => Yii::t('message', 'CHAPTERCODE_REQUIRED')),
array('verifyCode,', 'required','message' =>Yii::t('message', 'VERIFYCODE_REQUIRED')),
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'caseSensitive'=>true,'message' =>Yii::t('message', 'VERIFYCODE_INCORRECT')),
array('EmailAddress', 'unique','className'=>'User','attributeName'=>'EmailAddress','message'=>Yii::t('message', 'EMAILID_UNIQUE')),
array('PersonId', 'unique','className'=>'User','attributeName'=>'PersonId','message'=>"Person already exists."),
array('FailedLoginCount', 'safe'),
);
} elseif (isset($_POST['yt1']))
{
return array(
array('EmailAddress,', 'required','message' => Yii::t('message', 'USERNAME_REQUIRED')),
array('Password,', 'required','message' => Yii::t('message', 'PASSWORD_REQUIRED')),
array('FailedLoginCount', 'safe'),
);
}elseif (isset($_POST['savecontact'])||$this->memBelongsto==0)
{
return array(
array('EmailAddress,', 'required','message' => Yii::t('message', 'USERNAME_REQUIRED')),
array('Password,', 'required','message' => Yii::t('message', 'PASSWORD_REQUIRED')),
array('confirmPassword', 'required','message' => Yii::t('message', 'CONFIRM_PASSWORD_REQUIRED')),
array('Password','length', 'max' => 100, 'min' => 6,'tooShort' => Yii::t('message', 'PASSWORD_LENGTH')),
array('confirmPassword', 'compare', 'compareAttribute'=>'Password','message' => Yii::t('message', 'PASSWORD_COMPARE')),
array('EmailId,', 'required','message' => Yii::t('message', 'EMAILID_REQUIRED'),'except'=>'datavalid'),
array('EmailId','email','message'=>Yii::t('message', 'EMAILID_VALID'),'except'=>'datavalid'),
array('FailedLoginCount', 'safe'),
);
}else{
return array(
array('EmailAddress,EmailId, Password', 'required'),
array('PersonId, ActiveFlag, FailedLoginCount', 'numerical', 'integerOnly'=>true),
array('EmailAddress, Password', 'length', 'max'=>100),
array('confirmPassword,', 'required','message' => Yii::t('message', 'PASSWORD_REQUIRED')),
array('Password','length', 'max' => 100, 'min' => 6, 'tooShort' => Yii::t('message', 'PASSWORD_LENGTH')),
array('confirmPassword', 'compare', 'compareAttribute'=>'Password','message' => Yii::t('message', 'PASSWORD_COMPARE')),
array('chapterCode,', 'required','message' => Yii::t('message', 'CHAPTERCODE_REQUIRED')),
array('verifyCode,', 'required','message' =>Yii::t('message', 'VERIFYCODE_REQUIRED')),
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(),'caseSensitive'=>true,'message' =>Yii::t('message', 'VERIFYCODE_INCORRECT')),
array('FailedLoginCount', 'safe'),
);
}
}
驗證規則和這裏yt0
是yt0
規則將被應用提交註冊頁面上,因此對註冊按鈕的名字,我有另一種在該頁面上更改密碼的表單我只需要三個字段,更改密碼的提交按鈕是savecontact
,但會應用savecontact規則,但註冊按鈕規則衝突,因此註冊驗證無效。是否正確的方式正確的規則如上任何建議請......
感謝兄弟的答覆,我會嘗試這一點,更多的細節我會問是否有任何疑問 – rch