I want to force the Zend form into Twitter Bootstrap style. I currently iterate through the form fields and write the form info into my bootstrap div construction.
I
I tried Ron's Partial method, the result would like this which not Bootstrap 3 intended.
... Brand ... We know, in order to use bootstrap 3 predefined Form style, we need to define style to input element: form-control, rather than its wrapping element. My Partial way is as following. echo $this->form()->openTag($form); foreach ($form as $element) :?> getOption('required')) { $req = 'required'; } $type = $element->getAttribute('type'); $name = $element->getAttribute('name'); $label = $element->getLabel(); ?> formElement($element); ?> form()->closeTag(); Well, we could get the result. ... Brand ... How to attach custom styles into zf2 forms has mentioned : to add class attribute to the Form element. class TeaForm extends Form { public function __construct($name = null) { // we want to ignore the name passed parent::__construct('tea'); $this->add(array( 'name' => 'id', 'type' => 'Hidden', )); $this->add(array( 'name' => 'brand', 'type' => 'Text', 'options' => array( 'label' => 'Brand', ), /** **define class attribute** **/ 'attributes' => array( 'class' => 'form-control', ), )); .... It looks quite simple, but, the problem is the input element would be wrapped into the label element, which still not what Bootstrap 3 intended. Name ... In my opinion, the Partial method is still one flexible and light choice. Tea Box is one ZF2 practice, you could find all above mentioned code and description from Gibhub 0 讨论(0) 查看其它4个回答 发布评论: 提交评论 加载中... 验证码 看不清? 提交回复
We know, in order to use bootstrap 3 predefined Form style, we need to define style to input element: form-control, rather than its wrapping element.
My Partial way is as following.
echo $this->form()->openTag($form); foreach ($form as $element) :?> getOption('required')) { $req = 'required'; } $type = $element->getAttribute('type'); $name = $element->getAttribute('name'); $label = $element->getLabel(); ?> formElement($element); ?> form()->closeTag();
Well, we could get the result.
... Brand ...
How to attach custom styles into zf2 forms has mentioned : to add class attribute to the Form element.
class TeaForm extends Form { public function __construct($name = null) { // we want to ignore the name passed parent::__construct('tea'); $this->add(array( 'name' => 'id', 'type' => 'Hidden', )); $this->add(array( 'name' => 'brand', 'type' => 'Text', 'options' => array( 'label' => 'Brand', ), /** **define class attribute** **/ 'attributes' => array( 'class' => 'form-control', ), )); ....
It looks quite simple, but, the problem is the input element would be wrapped into the label element, which still not what Bootstrap 3 intended.
Name ...
In my opinion, the Partial method is still one flexible and light choice. Tea Box is one ZF2 practice, you could find all above mentioned code and description from Gibhub