簡體   English   中英

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中的bug檢查器)時,不會加載' 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不是函數

我認為您錯過了輸入錯誤字段:

<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版本,請全部刪除!

感謝大家!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM