Yii - 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(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>

------ 更新 2 ------

现在出现这个错误:

TypeError: jQuery(...).yiiactiveform 不是函数

我认为您错过了 error 个输入字段:

<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 版本,请全部删除!

谢谢大家!