0

reCAPTCHA フィールドでビュー スクリプト デコレータを使用したいと考えています。標準のビュー スクリプトをデコレータとして使用すると、出力はテキスト入力フィールドになります。これが私の標準的なフォーム フィールド ビュー スクリプトです。

<?php
$class = 'field ' . strtolower(end(explode('_',$this->element->getType())));
if ($this->element->isRequired()) {
    $class .= ' required';
}
if ($this->element->hasErrors()) {
    $class .= ' errors';
}
if (0 < strlen($this->element->class)) {
    $class .= ' ' . $this->element->class;
}
?>
<div class="<?php echo $class; ?>" id="field_<?php echo $this->element->getId(); ?>">
    <?php if (0 < strlen($this->element->getLabel())) {
        $labelAttribs = $this->element->getAttribs();
        if ($this->element->isRequired()) {
            $labelAttribs['escape'] = false;
            $this->element->setLabel($this->element->getLabel() . ' <span class="screenreader">required</span>');
        }
        echo $this->formLabel($this->element->getFullyQualifiedName(), $this->element->getLabel(), $labelAttribs);
    } ?>
    <span class="value"><?php echo $this->{$this->element->helper}(
        $this->element->getFullyQualifiedName(),
        $this->element->getValue(),
        $this->element->getAttribs()
    ); ?></span>
    <?php if (0 < strlen($this->element->getDescription())): ?>
        <div class="hint"><?php echo $this->element->getDescription(); ?></div>
    <?php endif; ?>
    <?php if ($this->element->hasErrors()): ?>
        <?php echo $this->formErrors($this->element->getMessages()); ?>
    <?php endif; ?>
</div>

私が変更する必要がある部分はこれであると確信しています:

<span class="value"><?php echo $this->{$this->element->helper}(
    $this->element->getFullyQualifiedName(),
    $this->element->getValue(),
    $this->element->getAttribs()
); ?></span>

...しかし、何に変更すればよいかわかりません。

4

1 に答える 1

1

結局のところ、これは私の質問に対する解決策と同じ方法で実現できます: How do I use ViewScripts on Zend_Form File Elements?

フォーム要素:

$this->addElement('captcha', 'captcha', array(
    'disableLoadDefaultDecorators' => true,
    'decorators' => array(
        'Captcha_ReCaptcha',
        array(
            'ViewScript',
            array(
                'viewScript' => '_form/recaptcha.phtml',
                'placement' => false,
            ),
        ),
    ),
    'label' => 'Verification',
    'required' => true,
    'captcha' => array(
        'pubkey' => $options['recaptcha']['pubkey'],
        'privkey' => $options['recaptcha']['privkey'],
        'theme' => 'white',
        'captcha' => 'reCaptcha',
    ),
));

ビュー スクリプトで、次のように reCAPTCHA コンテンツを出力します。

<?php echo $this->content; ?>
于 2012-06-25T19:25:52.373 に答える