2013-12-11 72 views
0

我使用Yii用戶,並對user/views/user/registration.php文件進行了一些修改。註冊表格後欄爲空

由於某種原因,即使我填寫名字和姓氏,它仍然說我把這些字段留空。任何想法爲什麼?

$form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id'=>'registration-form', 
    'type'=>'vertical', 
    'enableClientValidation'=>true, 
    'clientOptions'=>array(
     'validateOnSubmit'=>true, 
    ), 
)); 


<?php echo $form->textField($model,'email', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('email'))); ?> 

     <?php echo $form->passwordField($model,'password', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('password'))); ?> 

     <?php echo $form->passwordField($model,'verifyPassword', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('verifyPassword'))); ?> 

     <p class="text-seperator"> about you </p> 

     <?php echo $form->textField($profile,'firstname', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('firstname'), 'maxlength'=> 255)); ?> 

     <?php echo $form->textField($profile,'lastname', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('lastname'), 'maxlength'=> 255)); ?> 

,並在我的user/models/registrationform.php我有這個

class RegistrationForm extends User { 
     public $firstname; //added 
     public $lastname; //added 
     public $verifyPassword; 
     public $verifyCode; 

     public function rules() { 
      $rules = array(
       array('firstname, lastname, password, verifyPassword, email', 'required'), 
       array('firstname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect First Name (length between 3 and 225 characters).")), 
       array('lastname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect Last Name (length between 3 and 225 characters).")), 

......... 
} 
} 

使用他們用這種原始代碼填寫名字和姓氏...

$profileFields=Profile::getFields(); 
     if ($profileFields) { 
      foreach($profileFields as $field) { 
      ?> 
    <!--div class="row"--> 
     <?php echo $form->labelEx($profile,$field->varname); ?> 
     <?php 
     if ($widgetEdit = $field->widgetEdit($profile)) { 
      echo $widgetEdit; 
     } elseif ($field->range) { 
      echo $form->dropDownList($profile,$field->varname,Profile::range($field->range)); 
     } elseif ($field->field_type=="TEXT") { 
      echo$form->textArea($profile,$field->varname,array('rows'=>6, 'cols'=>50)); 
     } else { 
      echo $field->varname.'<br />'; 
      echo $form->textField($profile,$field->varname,array('size'=>60,'maxlength'=>(($field->field_size)?$field->field_size:255))); 
     } 
     ?> 
     <?php echo $form->error($profile,$field->varname); ?> 
    <!--/div--> 
      <?php 
      } 
     } 
+0

看來你似乎在使用2個不同的模型$ profile和$ model,爲什麼? – rabidmachine9

+0

原代碼使用兩者。從2個不同的表中讀取 – user2636556

+0

好吧,但似乎你只使用一個模型...也許你應該改變一切到$模型? – rabidmachine9

回答

0

我認爲你需要改變這個,

你已通過$model在這裏:

<?php echo $form->textField($model,'email', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('email'))); ?> 

,但你在這裏給$profile

<?php echo $form->textField($profile,'firstname', array('class' => 'input-block-level', 'placeholder' => $model->getAttributeLabel('firstname'), 'maxlength'=> 255)); ?> 

如果你看看生成html,你會發現,所產生的輸入具有不同的名稱

+0

裏面的名字一樣的東西。更新了我的問題.. – user2636556

0

我不知道爲什麼這個工程(將是偉大的是有人能詳細解釋)

但問題是這裏..

public function rules() { 
      $rules = array(
       array('firstname, lastname, password, verifyPassword, email', 'required'), 
       array('firstname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect First Name (length between 3 and 225 characters).")), 
       array('lastname', 'length', 'max'=>225, 'min' => 3,'message' => UserModule::t("Incorrect Last Name (length between 3 and 225 characters).")), 

......... 
} 
} 

名字,姓氏當這個被刪除有用。它仍然按需要設置。