5

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

3 Answers 3

10

You can also use

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

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

1
  • 1
    Just as another hint: every occurance of Attribute in ZF2 should always reference to a HTML-Attribute. All other stuff is referenced to as Option
    – Sam
    Dec 18, 2012 at 10:03
2

It works is using

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.