Property;RegForm.password2;is not defined. [ 新手入门 ]
<?php
class IndexController extends Controller
{
public function actionIndex()
{
$this->render("index");
}
public function actionReg()
{
$model=new RegForm;
if(isset($_POST['RegForm']))
{
// 收集用户输入的数据
$model->attributes=$_POST['RegForm'];
echo "dfs";
// 验证用户输入,并在判断输入正确后重定向到前一页
if($model->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
$this->render("reg",array('model'=>$model));
}
public function actionCheck()
{
if(isset($_POST['RegForm']))
{
// 收集用户输入的数据
$model->attributes=$_POST['RegForm'];
echo "dfs";
// 验证用户输入,并在判断输入正确后重定向到前一页
if($model->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
}
}
<?php
class RegForm extends CFormModel
{
public $username;
public $password;
public $rememberMe=false;
private $_identity;
public function rules()
{
return array(
// username and password are required
array('username, password', 'required'),
array('username','length','min'=>3,'max'=>12),
array('password','length','min'=>6,'max'=>16),
array('password','compare','compareAttribute'=>'password2'),
//array('email','email'),
array('rememberMe', 'boolean'),
);
}
public function authenticate($attribute,$params)
{
$this->_identity=new UserIdentity($this->username,$this->password);
if(!$this->_identity->authenticate())
{
$this->adderror('username','必须输入用户,且长度为3位');
$this->adderror('username','必须输入用户,且长度为3-12位');
$this->addError('password','必须输入密码,且长度为6-16位');
$this->addError('password','密码不相等');
}
}
}
?>
<div class="form">
<?php echo CHtml::beginForm($action='reg',$method='post',$htmlOptions=array('name'=>'RegForm')); ?>
<?php echo CHtml::errorSummary($model); ?>
<div class="row">
<?php echo CHtml::activeLabel($model,'username'); ?>
<?php echo CHtml::activeTextField($model,'username') ?>
</div>
<div class="row">
<?php echo CHtml::activeLabel($model,'password'); ?>
<?php echo CHtml::activePasswordField($model,'password') ?>
</div>
<div class='row'>
<?php echo CHtml::activeLabel($model,'password2'); ?>
<?php echo CHtml::activePasswordField($model,'password2') ?>
</div>
<div class="row rememberMe">
<?php echo CHtml::activeCheckBox($model,'rememberMe'); ?>
<?php echo CHtml::activeLabel($model,'rememberMe'); ?>
</div>
<div class="row submit">
<?php echo CHtml::submitButton('注册'); ?>
</div>
<?php echo CHtml::endForm(); ?>
</div><!-- form -->
南龙
注册时间:2012-01-05
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝0
- 金钱135
- 威望0
- 积分135