我有一个带有自定义验证的模型
class RegisterForm extends CFormModel
{
public $codiceMembro;
//...some more attributes
//validation
public function rules()
{
return array(
array('codiceMembro', 'codiceODataNascita'),
//...some more rules
);
}
// Declares attribute labels.
public function attributeLabels()
{
return array(
'codiceMembro'=>"a description",
//...some more labels
);
}
//My own custom validate function, always error for it
public function codiceODataNascita($attribute, $params){
$this->addError('codiceMembro','a bad message');
}
//...other model stuff
}
然后在视图中,在这里我如何插入模型
<?php
$model=new RegisterForm;
$form=$this->beginWidget('CActiveForm', array(
'id'=>'register-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
));
?>
<div class="row">
<?php echo $form->label($model, 'codiceMembro'); ?>
<?php echo $form->textField($model, 'codiceMembro');?>
<?php echo $form->error($model,'codiceMembro'); ?>
</div>
//...so on till the end of the code
我期望的是无论我输入什么,我都会收到错误消息
相反,对于此代码,一切都被验证为 OK