Yii Framework Forum: 验证规则添加密码一致不起作用 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

验证规则添加密码一致不起作用 Rate Topic: -----

#1 User is offline   Qo_O9 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 11-October 12

Posted 11 October 2012 - 10:08 PM

只有required这条验证起作用,其他的都不生效啊
class RegisterForm extends CFormModel
{

public $username;
public $password;
public $passwordConfirm;
public $nickname;
private $deviceCode;

public function rules()
{
return array(
array('password', 'compare', 'compareAttribute' => 'passwordConfirm', 'on' => 'register', 'message' => '密码不一致'),
array('username, password, passwordConfirm', 'required', 'message' => '请填写注册信息'),
array('username, nickname', 'unique', 'on' => 'register')); // 唯一,不能有重复记录
}
}

class SiteController extends Controller
{
public function actionRegister()
{
$model = new RegisterForm;

// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'register-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}

// collect user input data
if (isset($_POST['RegisterForm'])) {
$model->attributes = $_POST['RegisterForm'];
// validate user input and redirect to the previous page if valid
if ($model->validate() && $model->register())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the register form
$this->render('register', array('model' => $model));
}
}
0

#2 User is offline   Qo_O9 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 11-October 12

Posted 11 October 2012 - 10:30 PM

搞定了,够低级~ :-[
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users