Write hyperlink inside the Zend Form?

后端 未结 5 1528
无人及你
无人及你 2020-12-29 07:50

I am using Zend-Framework in my project. I made a login form using the Zend Form that contains the User Id and Passwords fields with a submit button. Everything is

相关标签:
5条回答
  • 2020-12-29 08:32

    Try this:

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

    Description decorator will add this text beside your field.

    0 讨论(0)
  • 2020-12-29 08:35

    For only decorators use directly in the form try:

            $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');
    
    0 讨论(0)
  • 2020-12-29 08:40

    You can use Zend_Form_Decorator_ViewScript

    Or, create a custom Zend_Form_Element to render HTML elements or ViewScript.

    0 讨论(0)
  • 2020-12-29 08:50

    In your viewscript file where you print the form, e.g. login.phtml

    echo $this->form;
    

    you can specify any other html markup, e.g. links

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

    So you actually do not write it in the form itself but in the view script where you echo the form.

    0 讨论(0)
  • 2020-12-29 08:51

    I've faced the same problem before, and solved it by creating a custom Zend_Form_Element_Html, as follows:

    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;
        }
    }
    

    So, in your form you just have to do the following:

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

    Hope this helps!

    0 讨论(0)
提交回复
热议问题