Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework 2 - Add Form class

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

like image 824
Ron Avatar asked Dec 18 '12 08:12

Ron


3 Answers

You can also use

$this->setAttributes(array(
    'action' => '/someurl',
    'method' => 'post',
    'class'  => 'form-horizontal'
));
like image 181
Diemuzi Avatar answered Nov 10 '22 18:11

Diemuzi


Alright, the trick is to use setAttribute twice!

Do this in the Form.php:

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

Reference Link is:

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

like image 33
Ron Avatar answered Nov 10 '22 19:11

Ron


It works is using

$this->setAttribute('method', 'post');
$this->setAttribute('class', 'form-horizontal');
like image 2
Nguyen Tien Pa Ven Avatar answered Nov 10 '22 19:11

Nguyen Tien Pa Ven