【问题标题】:Zend Form reCaptcha ViewScript DecoratorZend Form reCaptcha ViewScript 装饰器
【发布时间】:2012-06-25 18:27:03
【问题描述】:

我想在 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>

...但我不知道要改成什么。

【问题讨论】:

    标签: php zend-framework zend-form zend-form-element zend-decorators


    【解决方案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-03-18
      • 1970-01-01
      • 2011-08-09
      • 2010-12-10
      • 1970-01-01
      • 2011-01-09
      • 1970-01-01
      • 1970-01-01
      • 2011-11-27
      相关资源
      最近更新 更多