联系表单有效,但方法或闭包“刷新”给出错误


contact form works but method or closure "refresh" gives an error

我通过调整标准联系表单为联系表单制作了一个小部件,效果很好。电子邮件已发送,但在刷新时出现错误:

contact and its behaviors do not have a method or closure named "refresh".

当我引用页面时,错误消失了,并显示消息"我们会与您联系"。我一直在打破我的头,可能看错了方向,但找不到原因......

型:

    class ContactForm extends CFormModel
{
    public $gender;
    public $name;
    public $lastname;
    public $email;
    //public $subject;
    //public $body;
    //public $verifyCode;
    /**
     * Declares the validation rules.
     */
    public function rules()
    {
        return array(
            // name, email, subject and body are required
            array('name, lastname, email, gender', 'required'),
            // email has to be a valid email address
            array('email', 'email'),
            // verifyCode needs to be entered correctly
            //array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
        );
    }
    /**
     * Declares customized attribute labels.
     * If not declared here, an attribute would have a label that is
     * the same as its name with the first letter in upper case.
     */
    public function attributeLabels()
    {
        return array(
            'verifyCode'=>'Verification Code',
        );
    }
}

元件:

   class contact extends CWidget
{
    public function run()
    {
        $model=new ContactForm;
        if(isset($_POST['ContactForm']))
        {
            $model->attributes=$_POST['ContactForm'];
            if($model->validate())
            {
                $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
                $subject='Contact Kumbia Website '.$model->name.' '.$model->lastname;
                $headers="From: $name $lastname <{$model->email}>'r'n".
                    "Reply-To: {$model->email}'r'n".
                    "MIME-Version: 1.0'r'n".
                    "Content-type: text/plain; charset=UTF-8";
                $body='Deze persoon wil graag contact met ons!! ('.$model->gender.') Email: '.$model->email.' Abrazo Team Website...';
                mail(Yii::app()->params['adminEmail'],$subject,$body,$headers);
                Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
                $this->refresh();
            }
        }
        $this->render('_contact',array('model'=>$model));
    }
}

组件视图:

    <div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'contact-form',
    'enableClientValidation'=>true,
    'clientOptions'=>array(
        'validateOnSubmit'=>true,
    ),
)); ?>
    <div class="lijn"></div>
    <?php //echo $form->errorSummary($model); ?>
    <table>
        <tr>
            <td>
            </td>
            <td>
                <?php
                    echo $form->radioButtonList($model, 'gender',
                        array(  'Mannetje' => 'MALE',
                                'Vrouwtje' => 'FEMALE' ),
                        array( 'separator' => " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; " ) );
                ?>
                <?php echo $form->error($model,'gender'); ?>
            </td>
            <td>
            </td>
            <td>
            </td>
        <tr>
        <tr>
            <td>
                FIRST NAME
            </td>
            <td style="width:100px;">
                <?php //echo $form->labelEx($model,'name'); ?>
                <?php echo $form->textField($model,'name'); ?>
                <?php echo $form->error($model,'name'); ?>
            </td>
            <td>
                LAST NAME
            </td>
            <td>
                <?php //echo $form->labelEx($model,'lastname'); ?>
                <?php echo $form->textField($model,'lastname'); ?>
                <?php echo $form->error($model,'lastname'); ?>
            </td>
        <tr>
        <tr>
            <td>
                EMAIL ADDRESS
            </td>
            <td>
                <?php //echo $form->labelEx($model,'email'); ?>
                <?php echo $form->textField($model,'email'); ?>
                <?php echo $form->error($model,'email'); ?>
            </td>
            <td>
            </td>
            <td>
            </td>
        <tr>
    </table>
    <div class="lijn2"></div>
    <div class="row buttons">
        <?php echo CHtml::submitButton('Submit'); ?>
    </div>
<?php $this->endWidget(); ?>
</div><!-- form -->
<?php endif; ?>

主.php

<?php $this->widget('application.components.contact'); ?>

有谁知道我在这里做错了什么?

谢谢!

此错误意味着您正在尝试从任何 yii 组件调用不存在的结束方法。

您的contact小部件中有$this->refresh();。我猜你想要$model->refresh(),但这只来自CActiveRecord的方法,而不是来自CFormModel的方法。只需删除带有$this->refresh();的线,它应该没问题。