Zend Framework 2 - Add Form class

Ron picture Ron · Dec 18, 2012 · Viewed 10.4k times · Source

I just can't find the answer... Is there a way to pass a CSS class to my open-form-tag?

For example I want to create a form with the class ''form-horizontal''.

The docs say this:

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

But how adding the form class name?

Edit: I tried adding this to my Form.php but nothing happend...

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

Thanks,

Ron

Answer

Diemuzi picture Diemuzi · Dec 20, 2012

You can also use

$this->setAttributes(array(
    'action' => '/someurl',
    'method' => 'post',
    'class'  => 'form-horizontal'
));