5

我只是找不到答案...有没有办法将 a 传递CSS class给 my open-form-tag

例如,我想创建一个带有“form-horizo​​ntal”类的表单。

文档是这样说的:

// Render the opening tag
echo $this->form()->openTag($form);
// <form action="/contact/process" method="post">

但是如何添加表单类名?

编辑:我尝试将此添加到我的 Form.php 但没有发生任何事情......

public function getOptions()
{
    return array('class' => 'form-horizontal');
}

谢谢,

罗恩

4

3 回答 3

10

你也可以使用

$this->setAttributes(array(
    'action' => '/someurl',
    'method' => 'post',
    'class'  => 'form-horizontal'
));
于 2012-12-20T15:26:24.580 回答
3

好吧,诀窍是使用setAttribute两次!

在 Form.php 中执行此操作:

$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form-horizontal');

参考链接是:

http://framework.zend.com/manual/2.0/en/user-guide/forms-and-actions.html

于 2012-12-18T08:58:30.637 回答
2

它的工作原理是使用

$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form-horizontal');
于 2013-06-14T04:07:16.180 回答