2011-05-04 52 views
15

我在我的項目中使用了Zend-Framework。我使用Zend表單創建了一個登錄表單,其中包含用戶標識和密碼字段以及提交按鈕。在登錄表單中一切正常。在Zend Form中寫超鏈接?

如何添加登錄表單這是一個用於的註冊等爲忘記密碼兩個超鏈接?

回答

11

我之前遇到過同樣的問題,並通過創建自定義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); 

希望這會有所幫助!

+0

嘿感謝,這是我在問什麼..... – Pushpendra 2011-05-12 06:30:16

7

在您打印表單的視圖文件中,例如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); 

描述裝飾會添加字段旁邊這個文本。

1

僅用於裝飾的形式嘗試直接使用:

 $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');