0

ポートレットを使用して連絡先フォームを表示しています。これは、標準で生成される静的ページとまったく同じです。同じ ContactForm モデルを使用しています。フォームは表示されますが、キャプチャは表示されず、「CCaptchaValidator.action "captcha" is invalid. Unable to find such an action in the current controller.」と報告されます。

私は yii を初めて使用するので、すべてを理解するのに非常に多くの時間がかかります。それを機能させるためにシェルが行う簡単なアドバイスはありますか?

一番!

Yii::import('zii.widgets.CPortlet');

class ContactFormCard extends CPortlet
{
    public $title='Contact';

protected function renderContent()
{
    $model=new ContactForm;
    if(isset($_POST['ContactForm']))
    {
        $model->attributes=$_POST['ContactForm'];
        if($model->validate())
            $this->controller->refresh();
    }
    $this->render('contactFormCard',array('model'=>$model));
}
public function actions()
{
    return array(
        'captcha'=>array(
            'class'=>'CCaptchaAction',
            'backColor'=>0xFFFFFF,
        ),
    );
}

}

およびポートレット ビュー:

<?php if(CCaptcha::checkRequirements()): ?>
    <div class="row">
        <?php echo $form->labelEx($model,'verifyCode'); ?>
        <div>
        <?php $this->widget('CCaptcha'); ?>
        <?php echo $form->textField($model,'verifyCode'); ?>
        </div>
        <div class="hint">Please enter the letters as they are shown in the image above.
        <br/>Letters are not case-sensitive.</div>
        <?php echo $form->error($model,'verifyCode'); ?>
    </div>
    <?php endif; ?>
4

1 に答える 1

2

SiteController.php に以下を追加します。

    public function actions() {
        return array(
            'captcha' => array(
                'class' => 'CCaptchaAction',
            'backColor' => 0xFFFFFF,
            ),

            // [...]
        );
    }

ContactForm.php に以下を追加します。

public function rules() {
    return array(
        // [...]

        array('verifyCode', 'captcha', 'allowEmpty' => !CCaptcha::checkRequirements(), 'message' => Yii::t('formsErros', 'Código de verificação incorreto.')),

        // [...]
    );
}

あなたの中でview.php

<!-- [...] -->

<?php if(CCaptcha::checkRequirements()): ?>
    <div class="captcha">
            <?=$form->labelEx($contactFormModel, 'verifyCode')?>
            <?php $this->widget('CCaptcha', array('clickableImage' => true, 'showRefreshButton' => true, 'imageOptions' => array('id' => 'captchaContactForm', 'class' => 'clickableCursor'), 'buttonLabel' => '')); ?>
            <?=$form->textField($contactFormModel, 'verifyCode', array('class' => 'verticalAlignBottom'))?> 
            <?=$form->error($contactFormModel, 'verifyCode')?>
    </div>
<?php endif; ?>

<!-- [...] -->
于 2012-08-13T13:08:45.077 に答える