LoginSignup
2

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');
}

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