我有一个 Yii 表格,它收集三个模型的数据。我在更改和提交时使用 ajaxvalidation:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'offer-form',
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'clientOptions' => array(
'validateOnChange'=>true,
'validateOnSubmit'=>true,
)
)); ?>
现在的问题是只有前三个输入得到验证,这些输入的代码:
1:
<div class="input-bg wide-input">
<?php
//fill this field after selecting newspaper
echo $form->hiddenField($newspaper, 'id'); ?>
<?php echo $form->textField($newspaper, 'name', array('maxlength' => 45, 'placeholder'=>'Krantnaam')); ?>
<?php echo $form->error($newspaper, 'name', array('class'=>'error')); ?>
</div>
<a class="button gray-button">Aanbieden</a>
2和3:
<div class="input-bg linked-input">
<?php echo $form->textField($address, 'postalcode', array('maxlength' => 45, 'placeholder'=>'Postcode')) ?>
<?php echo $form->error($address, 'postalcode'); ?>
</div>
<div class="input-bg linked-input">
<?php echo $form->textField($address, 'street_number', array('maxlength' => 45, 'placeholder'=>'Huisnummer')); ?>
<?php echo $form->error($address, 'street_number'); ?>
</div>
这三个输入服务于两个模型,它们是$newspaper and $address
。现在的情况是,这三个输入已完全验证(在更改和提交时),而其他七个输入未验证,例如未验证的输入之一:
<div class="input-bg linked-input">
<?php echo $form->textField($offer, 'firstname', array('maxlength' => 45, 'placeholder'=>'Voornaam')); ?>
<?php echo $form->error($offer, 'firstname'); ?>
</div>
最后,我将发布我的控制器代码:
$this->performAjaxValidation($offer, 'offer-form');
$this->performAjaxValidation($address, 'offer-form');
$this->performAjaxValidation($newspaper, 'offer-form');
if(Yii::app()->getRequest()->getIsAjaxRequest()) {
echo CActiveForm::validate( array($address));
echo CActiveForm::validate( array($offer));
echo CActiveForm::validate( array($newspaper));
print_r($_POST);
die();
//Yii::app()->end();
}
如果我提交或更改表单,我会返回 JSON,其中包含未经验证的字段的错误,但它们不会收到错误状态。
我希望有人可以看到错误或其他任何东西。
问候,