CActiveForm客户端不工作


Yii - CActiveForm client-side not working

我需要使用CActiveForm验证表单,但在客户端。

下面是我初始化小部件和错误的代码:

<?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'idX',
        'enableAjaxValidation' => false,
        'enableClientValidation'=> true,
        'clientOptions'=>array('onSubmit'=>true),
        'htmlOptions' => array(
            'enctype' => 'multipart/form-data'
        ),
    ));
    ?>
<?= $form->errorSummary($model); ?>

之后,我有了输入,最后我有了这个:

<?php $this->endWidget(); ?>

当我提交的形式,当我按下F12 (bug inspector in mozilla), ' jquery.yiiactiveform.js '没有加载。当我使用这个小部件时,应该包含这个js文件。

——更新

public function rules() {
    return array(
        //Always required
        array('p_first_name, p_last_name, p_title, p_phone, p_phone2, p_fax, p_email, user, password, clientType', 'required'),
        //just company
        array('c_name, c_postal_code, c_location, c_country, c_activity, c_nif, c_website', 'required', 'on' => 'company'),
        array('c_country, c_activity', 'numerical', 'integerOnly' => true),
        array('c_name, c_location, c_website, p_first_name, p_last_name, p_email', 'length', 'max' => 255),
        array('c_postal_code', 'length', 'max' => 8),
        array('c_nif', 'length', 'max' => 9),
        array('p_title', 'length', 'max' => 25),
        array('p_phone, p_phone2, p_fax', 'length', 'max' => 15),
        array('user, password', 'length', 'max' => 100),
        // The following rule is used by search().
        // @todo Please remove those attributes that should not be searched.
        array('id_client, c_name, c_postal_code, c_location, c_country, c_activity, c_nif, c_website, p_first_name, p_last_name, p_title, p_phone, p_phone2, p_fax, p_email, user, password', 'safe', 'on' => 'search'),
    );
}

和一个输入示例:

<div class="form-group">
            <?= $form->labelEx($model, 'p_phone', array('class' => 'col-sm-2 control-label')); ?>
            <div class="col-sm-10">
                <?= $form->textField($model, 'p_phone', array('class' => 'form-control', 'placeholder' => Yii::t('clients/register', 'Insira o contacto telefónico do empresário.'))); ?>
            </div>
        </div>

------ UPDATE 2 -------

现在出现这个错误:

TypeError: jQuery(…)。Yiiactiveform不是函数

我想你错过了输入的错误字段:

<div class="form-group">
    <?= $form->labelEx($model, 'p_phone', array('class' => 'col-sm-2 control-label')); ?>
    <div class="col-sm-10">
        <?= $form->textField($model, 'p_phone', array('class' => 'form-control', 'placeholder' => Yii::t('clients/register', 'Insira o contacto telefónico do empresário.'))); ?>
    </div>
    <?= $form->error($model, 'p_phone'); ?>
</div>

修复!

我有两个版本的jQuery,所以它会引起冲突。因此,如果您在main.php上有一个或两个jQuery版本,请全部删除!

谢谢大家!