2015-09-23 49 views
2

我需要使用CActiveForm來驗證表單,但在客戶端。Yii - 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> 

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

現在正出現這樣的錯誤:

類型錯誤:jQuery的(...)yiiactiveform不是一個函數

+0

請提供您的輸入和規則 –

回答

0

定了!

我有兩個版本的jQuery,所以這是導致衝突。所以,如果你有,main.php上的一個或兩個jQuery版本,請全部刪除!

謝謝大家!

0

我想你好想​​字段進行輸入:

<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> 
+0

正是我要指向下:) :) – Criesto

+0

@Criesto對不起,我不明白你的意思? –

+0

沒有工作:/ –

相關問題