【问题标题】:Write hyperlink inside the Zend Form?在 Zend Form 中写超链接?
【发布时间】:2011-08-18 11:24:33
【问题描述】:

我在我的项目中使用 Zend-Framework。我使用 Zend 表单制作了一个登录表单,该表单包含带有提交按钮的用户 ID 和密码字段。登录表单中一切正常。

如何在登录表单中添加两个超链接,一个用于注册,另一个用于忘记密码

【问题讨论】:

    标签: zend-framework zend-form


    【解决方案1】:

    我之前也遇到过同样的问题,通过创建自定义 Zend_Form_Element_Html 解决了,如下:

    class Zend_Form_Element_Html extends Zend_Form_Element_Xhtml {
        /**
         * Default form view helper to use for rendering
         * @var string
         */
        public $helper = 'formNote';
    
        public function isValid($value, $context = null) {
            return true;
        }
    }
    

    因此,在您的表单中,您只需执行以下操作:

    $tag = new Zend_Form_Element_Html('forgetPassword');
    $tag->setValue('<a href="/forgotten-pwd">Forgotten your password?</a>');
    $this->addElement($tag);
    

    希望这会有所帮助!

    【讨论】:

      【解决方案2】:

      在您打印表单的 viewscript 文件中,例如login.phtml

      echo $this->form;
      

      您可以指定任何其他 html 标记,例如链接

      echo "<p><a href='".$this->url ( array ('controller' => 'authentication',
                                              'action' => 'lostPW' ) )."'>
            Lost pw </a></p>";
      

      所以你实际上并没有在表单本身中编写它,而是在你回显表单的视图脚本中编写它。

      【讨论】:

        【解决方案3】:

        试试这个:

        $passwordElement->setDescription('<a href="">Forgot password?</a>');
        $passwordElement->getDecorator('Description')->setOption('escape', false);
        

        描述装饰器将在您的字段旁边添加此文本。

        【讨论】:

          【解决方案4】:

          您可以使用Zend_Form_Decorator_ViewScript

          或者,创建一个自定义 Zend_Form_Element 来呈现 HTML 元素或 ViewScript。

          【讨论】:

            【解决方案5】:

            仅装饰器直接在表单中使用:

                    $this->addElement(new Zend_Form_Element_Note(array(
                        'name' => 'forgotten',
                        'value' => __('Forgot your password?'),
                        'decorators' => array(
                            array('ViewHelper'),
                            array('HtmlTag', array(
                                'tag' => 'a',
                                'href' => $this->getView()->url(array(
                                    'remind'
                                ))
                            )),
            
                        )
                    )), 'forgotten');
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2014-02-01
              • 1970-01-01
              • 1970-01-01
              • 2013-05-24
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多