20

我正在尝试以 zend 形式添加纯文本节点 - 目的是仅显示一些静态文本。

问题是 - 我不知道有任何这样的方法。

我使用了“描述”,但必须附加到表单元素。

有没有办法简单地将一些文本显示为表单的一部分?Zend 将所有内容都视为表单元素,因此我不能将其打印出来。

例如:

下面将测试你对某某的能力。. . .

ETC...

有什么想法吗?

4

7 回答 7

38

Zend 有一个表单注释视图助手(Zend_View_Helper_FormNote),您可以使用它来添加文本。

只需创建一个新的表单元素(/application/forms/Element/Note.php):

class Application_Form_Element_Note extends Zend_Form_Element_Xhtml  
{  
    public $helper = 'formNote';  
}

在您的表格中:

$note = new Application_Form_Element_Note(
    'test',
    array('value' => 'This is a <b>test</b>')
);
$this->addElement($note);
于 2010-10-12T09:35:59.100 回答
10

添加具有非转义描述的隐藏元素就可以了。

$form->addElement('hidden', 'plaintext', array(
    'description' => 'Hello world! <a href="#">Check it out</a>',
    'ignore' => true,
    'decorators' => array(
        array('Description', array('escape'=>false, 'tag'=>'')),
    ),
));

完美运行。它仍然附加到一个元素,但是,它不是以这种方式呈现的。

代码取自: http: //paveldubinin.com/2011/04/7-quick-tips-on-zend-form/

于 2012-07-12T09:21:08.577 回答
6

可能有更好的方法,但我使用自定义表单元素和视图助手创建了一个段落。对于如此简单的事情,似乎有很多代码。如果您找到了更简单的方法,请告诉我。

//From your form, add the MyParagraph element
$this->addElement(new Zend_Form_Element_MyParagraph('myParagraph'));

class Zend_Form_Element_MyParagraph extends Zend_Form_Element
{
    public $helper = 'myParagraph';
    public function init()
    {
        $view = $this->getView();
    }
}

class Zend_View_Helper_MyParagraph extends Zend_View_Helper_FormElement {

    public function init() {
    }

    public function myParagraph() {
        $html = '<p>hello world</p>';
        return $html;
    }

}
于 2010-03-18T17:01:18.190 回答
6

有点晚了,但为了社区的利益,我想我还是会把它扔进去。

爱音一针见血。如果您想在 Zend_Form 中使用文本,您需要 FormNote。但是,您可以使用它而无需扩展 Zend_Form_Element_Xhtml。请参见下面的示例:

$text = new Zend_Form_Element_Text('myformnote');
$text->setValue("Text goes here")
     ->helper = 'formNote';

请注意,您可以将 text 和 html 与 formNote 帮助器一起使用。

于 2013-04-09T17:43:33.077 回答
5

此功能通过 Zend_Form_Element_Note 内置到 Zend 中。

$note = new Zend_Form_Element_Note('forgot_password');
$note->setValue('<a href="' . $this->getView()->serverUrl($this->getView()->url(array('action' => 'forgot-password'))) . '">Forgot Password?</a>');
于 2013-11-15T02:02:51.557 回答
3

我遇到了同样的问题,并决定最好不要使用 Zend_Form,而是直接使用视图助手(如 Ruby on Rails)并在模型上验证。

于 2010-03-04T17:07:52.813 回答
0

这个单线对我有用:

$objectForm->addElement(new Zend_Form_Element_Note('note', array('value' => 'Hello World')));
于 2018-12-12T12:18:20.607 回答