登记表格邮政领域为空

时间:2013-12-11 11:17:47

标签: yii yii-extensions

我正在使用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
            }
        }

2 个答案:

答案 0 :(得分: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 ,您会注意到生成的输入具有不同的名称

答案 1 :(得分: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).")),

.........
}
}

名字,姓氏,当删除它时,它可以正常工作。它仍然按要求设置。