Zend Form reCaptcha ViewScript Decorator
我想在 reCAPTCHA 字段上使用视图脚本装饰器。如果我将标准视图脚本用作装饰器,则输出是文本输入字段。这是我的标准表单字段视图脚本:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<?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; } ?> " 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())): ?> <?php echo $this->element->getDescription(); ?> <?php endif; ?> <?php if ($this->element->hasErrors()): ?> <?php echo $this->formErrors($this->element->getMessages()); ?> <?php endif; ?> |
我很确定我需要更改的部分是:
1
2 3 4 5 |
<span class="value"><?php echo $this->{$this->element->helper}(
$this->element->getFullyQualifiedName(), $this->element->getValue(), $this->element->getAttribs() ); ?></span> |
…但我不知道要改成什么。
事实证明,这可以与我的问题的解决方案相同的方式完成:如何在 Zend_Form 文件元素上使用 ViewScripts?
表单元素:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$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 内容如下:
1
|
<?php echo $this->content; ?>
|
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268546.html