0

我对放置在 yii 表单中每个字段底部的内置错误消息有问题。创建失败后,这些错误消息应该会闪烁。

我希望有人可以帮助我解决这个问题。^^

这是我的代码。

模型:

public function rules() {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
    array('quantity,unit_cost', 'required','message'=>'Please enter a value for {attribute}.'),
}

控制器:

public function actionCreate() {
    $model=new BaseSiReceivedItem;

    if(isset($_POST['BaseSiReceivedItem']))
    {
        $model->attributes=$_POST['BaseSiReceivedItem'];
        if($model->save()){
        if(Yii::app()->request->isAjaxRequest){
            if($success){
                echo 'success';
                return true;
            }else{
                echo 'fail';
                return true;
            }
        }
        }else{
            $this->redirect(array('BaseIar/createItem'));
        }
    }
}

看法:

    <tr>
        <td><?php echo $form->labelEx($model,'quantity'); ?></td>
        <td>
            <?php echo $form->textField($model,'quantity', array('id'=>'new-base-si-received-item-quantity','disabled'=>'')); ?>
            <?php echo $form->error($model,'quantity'); ?>
        </td>
    </tr>   
    <tr>
        <td><?php echo $form->labelEx($model,'unit_cost'); ?></td>
        <td>
            <?php echo $form->textField($model,'unit_cost',array('size'=>10,'maxlength'=>10,'id'=>'new-base-si-received-item-unit_cost','disabled'=>'')); ?>
            <?php echo $form->error($model,'unit_cost'); ?>
        </td>
    </tr>   
4

0 回答 0