2014-10-30 57 views
0

我試圖在表單上使用yii的客戶端驗證。服務器端驗證工作正常,但我無法使用客戶端驗證。輸入上的默認focus不起作用。我還在CActiveForm小部件中添加了enableClientValidation => true。我究竟做錯了什麼?enableClientValidation不能在yii中工作1.1.14

這裏是一個視圖文件:

<?php 
/* @var $this CdAddBusinessController */ 
/* @var $model CdAddBusiness */ 
/* @var $form CActiveForm */ 
?> 

<!--=== Content Part ===--> 
<div class="container"> 
    <div class="row"> 
     <div class="col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2"> 
      <div class="reg-header"> 
        <h2>Register a new account</h2> 
        <p>Already Signed Up? Click <a href="<?php echo Yii::app()->request->baseUrl; ?>/site/clogin" class="color-green">Sign In</a> to login your account.</p>      
      </div> 

      <?php $form=$this->beginWidget('CActiveForm', array(
      'id'=>'consumer-form', 
      'enableClientValidation'=>true, 
      'focus'=>array($model,'consumer_first_name'), 
     )); ?> 

     <!-- Display Sucess Messages from the Controller --> 
     <?php if(Yii::app()->user->hasFlash('register')): ?> 
      <div class="flash-success" style="color:red;text-align:center;font-weight:bold;"> 
       <?php echo Yii::app()->user->getFlash('register'); ?> 
      </div> 
     <?php endif; ?> 

     <div class="row"> 
      <div class="col-sm-6">  
      <?php echo $form->textField($model,'consumer_first_name', array('class'=>'form-control margin-bottom-20', 'placeholder'=>'First Name')); ?> 
      </div> 
      <div style="color:red;text-align:center;font-family:verdana;font-size:12px;font-weight:bold;"> 
        <?php echo $form->error($model,'consumer_first_name'); ?>  
       </div> 
      <div class="col-sm-6">  
       <?php echo $form->textField($model,'consumer_last_name', array('class'=>'form-control margin-bottom-20', 'placeholder'=>'Last Name')); ?> 
      </div> 
      <div style="color:red;text-align:center;font-family:verdana;font-size:12px;font-weight:bold;"> 
       <?php echo $form->error($model,'consumer_last_name'); ?> 
      </div> 
     </div> 
      <div class="row"> 
       <div class="col-sm-6">  
       <?php echo $form->textField($model,'consumer_tin', array('class'=>'form-control margin-bottom-20', 'placeholder'=>'TIN')); ?> 
      </div> 

       <div style="color:red;text-align:center;font-family:verdana;font-size:12px;font-weight:bold;"> 
       <?php echo $form->error($model,'consumer_tin'); ?>  
        </div> 

        <div class="col-sm-6">   
       <?php echo $form->textField($model,'consumer_email', array('class'=>'form-control margin-bottom-20', 'placeholder'=>'Email')); ?> 
       </div> 

       <div style="color:red;text-align:center;font-family:verdana;font-size:12px;font-weight:bold;"> 
       <?php echo $form->error($model,'consumer_email'); ?>  
        </div> 
      </div> 
       <hr> 

       <div class="row"> 
        <div class="col-lg-6 text-right"> 
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Register' : 'Save', array('class'=>'btn-u')); ?> 
        </div> 
       </div> 
      <!--</form>--> 
     </div> 
    </div> 
</div><!--/container-->  
<?php $this->endWidget(); ?> 
<!--=== End Content Part ===--> 

這裏的模型:

<?php 


class Rconsumer extends CActiveRecord 
{ 
    /** 
    * @return string the associated database table name 
    */ 
    //public $message; 

    public function tableName() 
    { 
     return 'cd_consumer_users'; 
    } 

    /** 
    * @return array validation rules for model attributes. 
    */ 
    public function rules() 
    { 
     return array(
      array('consumer_first_name, consumer_last_name, consumer_tin, consumer_email, consumer_reg_date, status', 'required'), 
      array('consumer_email', 'email'), 
      array('consumer_email', 'unique'), 
     ); 
    } 

    /** 
    * @return array customized attribute labels (name=>label) 
    */ 
    public function attributeLabels() 
    { 
     return array(
      'consumer_id' => 'Consumer', 
      'consumer_first_name' => 'First Name', 
      'consumer_last_name' => 'Last Name', 
      'consumer_tin' => 'TIN', 
      'consumer_email' => 'Email', 
      'consumer_password' => 'Password', 
      'consumer_repassword' => 'Retype Password', 
     ); 
    } 

    /** 
    * Retrieves a list of models based on the current search/filter conditions. 
    * 
    * Typical usecase: 
    * - Initialize the model fields with values from filter form. 
    * - Execute this method to get CActiveDataProvider instance which will filter 
    * models according to data in model fields. 
    * - Pass data provider to CGridView, CListView or any similar widget. 
    * 
    * @return CActiveDataProvider the data provider that can return the models 
    * based on the search/filter conditions. 
    */ 
    public function search() 
    { 
     // @todo Please modify the following code to remove attributes that should not be searched. 

     $criteria=new CDbCriteria; 

     $criteria->compare('consumer_id',$this->consumer_id); 
     $criteria->compare('consumer_first_name',$this->consumer_first_name,true); 
     $criteria->compare('consumer_last_name',$this->consumer_last_name,true); 
     $criteria->compare('consumer_tin',$this->consumer_tin,true); 
     $criteria->compare('consumer_email',$this->consumer_email,true); 
     $criteria->compare('consumer_password',$this->primary_contact_name,true); 

     return new CActiveDataProvider($this, array(
      'criteria'=>$criteria, 
     )); 
    } 

    /** 
    * Returns the static model of the specified AR class. 
    * Please note that you should have this exact method in all your CActiveRecord descendants! 
    * @param string $className active record class name. 
    * @return CdAddBusiness the static model class 
    */ 
    public static function model($className=__CLASS__) 
    { 
     return parent::model($className); 
    } 
} 
+0

顯示模型規則集 – gvgvgvijayan 2014-10-30 07:12:43

+0

添加模型文件。 – Kanav 2014-10-30 07:20:08

+0

你清除了瀏覽器緩存並檢查了嗎? – gvgvgvijayan 2014-10-30 07:26:09

回答