谁一开始就是大神?

yii表单验证[1.1]

model:

public $bPoint;
public $bCard;

/**
 * @return string the associated database table name
 */
public function tableName()
{
	return 'carfree';
}

/**
 * @return array validation rules for model attributes.
 */
public function rules()
{
	// NOTE: you should only define rules for those attributes that
	// will receive user inputs.
	return array(
		array('openid, carmark,bCard realname, telephone, bTime, bArea', 'required'),
		array('flg, service, quality,card_id', 'numerical', 'integerOnly'=>true),
		array('openid, carmark, realname', 'length', 'max'=>50),
		array('telephone, cTime, qTime, sTime, wTime, pTime', 'length', 'max'=>13),
		array('bFlg, quser, suser, wuser', 'length', 'max'=>20),
		array('bArea', 'length', 'max'=>200),
	    array('carmark','match','pattern'=>'/^[\x{4e00}-\x{9fa5}]{1}[a-zA-Z]{1}[a-zA-Z_0-9]{4}[\x{4e00}-\x{9fa5}A-Za-z0-9]{1}$/u'),
	    array('bCard','checkbank'),
		// The following rule is used by search().
		//  Please remove those attributes that should not be searched.
		array('id, openid, carmark, realname, telephone, bTime, bFlg, bArea,bCity,bPoint, cTime, qTime, flg, sTime, wTime, service, quality, pTime, quser, suser, wuser, card_id,bCard', 'safe', 'on'=>'search'),
	);
}

public function  checkbank($attribute,$params)
{
    $card = $this->bCard;
    if($card != '222')
    {
       $this->addError('bCard','银行卡号有误');  
    }
}

views

<?php $form = $this->beginWidget('CActiveForm',array('id'=>'detailForm','enableAjaxValidation'=>false,'enableClientValidation'=>true,'clientOptions' => array('validateOnSubmit'=>true))); ?>
<?php if($flg == 2):?>
<div class="tpy-road-list clearfix">
<div class="tpy-road-lb left"><?php echo $form->label($model,'bCard');?></div>
<div class="tpy-road-input left">
<?php echo $form->textField($model,'bCard',array(
    'class'=>'road-input-txt','placeholder'=>'请输入银行卡号'));?>
<?php echo $form->error($model,'bCard');?>
</div>
</div>
<?php endif;?>

<div class="tpy-road-list clearfix">
<div class="tpy-road-lb left"><?php echo $form->label($model,'carmark');?></div>
<div class="tpy-road-input left">
<?php echo $form->textField($model,'carmark',array(
    'class'=>'road-input-txt','placeholder'=>'请输入车牌号','value'=>$user['carmark']));?>
<?php echo $form->error($model,'carmark');?>
	
</div>
</div>

controller

$flg = $_REQUEST['flg'];
$model = new CarFree;
$model->bCity = 4;
$openid = Yii::app()->session['openID'];
if($openid == '')
{
	echo '您的授权已失效,请重新授权';
}else{
    $user = Publicuser::model()->findByAttributes(array('openid'=>$openid));
}
if($user['realname'] == '微信用户' || $user['realname'] == '微信客户')
{
    $user['realname'] = '';
}

if(isset($_POST['Carfree']))
{
    $model->attributes=$_POST['Carfree'];

    // var_dump($model);exit;
    if($model->validate())
    {
        echo '222';  
    }
}

小弟实在不知model 里的验证方法有何问题,但是一点提交就报错
属性 “Carfree.bCard realname” 未被定义.

rules里的bCard realname是什么鬼?
是指bCard,realname?

赞(0) 打赏
未经允许不得转载:菜鸟之家 » yii表单验证[1.1]

评论 抢沙发

登录

找回密码

注册