2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Zend\Formで任意のフォームに twitter bootstrap horizontal 対応クラス属性を追加する。

Last updated at Posted at 2012-09-22
bugController.php
<?php
$form = new \Application\Form\ContactForm;
foreach ($form as $element) {
    $labelAttributes = $element->getLabelAttributes();
    if (isset($labelAttributes['class'])) {
        if (false === strpos('control-label', $labelAttributes['class'])) {
            $labelAttributes['class'] .= ' control-label';
        }
    }
    else {
        $labelAttributes['class'] = 'control-label';
    }
    $element->setLabelAttributes($labelAttributes);
}

if ($class = $form->getAttribute('class')) {
    if (false === strpos('form-horizontal', $class)) {
        $form->setAttribute('class', $class . ' form-horizontal');
    }
}
else {
    $form->setAttribute('class', 'form-horizontal');
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?