/**
  * Render buttons markup
  * @param array $aButtons
  * @return string
  */
 protected function renderButtons(array $aButtons, $bJustified = false)
 {
     $sMarkup = '';
     foreach ($aButtons as $oButton) {
         if (is_array($oButton) || $oButton instanceof \Traversable && !$oButton instanceof \Zend\Form\ElementInterface) {
             $oFactory = new \Zend\Form\Factory();
             $oButton = $oFactory->create($oButton);
         } elseif (!$oButton instanceof \Zend\Form\ElementInterface) {
             throw new \LogicException(sprintf('Button expects an instanceof \\Zend\\Form\\ElementInterface or an array / \\Traversable, "%s" given', is_object($oButton) ? get_class($oButton) : gettype($oButton)));
         }
         $sButtonMarkup = $this->getFormElementHelper()->__invoke($oButton);
         $sMarkup .= $bJustified ? sprintf(self::$buttonGroupJustifiedFormat, $sButtonMarkup) : $sButtonMarkup;
     }
     return $sMarkup;
 }
 /**
  * Render addo-on markup
  * @param string $aAddOnOptions
  * @throws \InvalidArgumentException
  * @throws \LogicException
  * @return string
  */
 protected function renderAddOn($aAddOnOptions)
 {
     if (empty($aAddOnOptions)) {
         throw new \InvalidArgumentException('Addon options are empty');
     }
     if ($aAddOnOptions instanceof \Zend\Form\ElementInterface) {
         $aAddOnOptions = array('element' => $aAddOnOptions);
     } elseif (is_scalar($aAddOnOptions)) {
         $aAddOnOptions = array('text' => $aAddOnOptions);
     } elseif (!is_array($aAddOnOptions)) {
         throw new \InvalidArgumentException('Addon options expects an array or a scalar value, "' . gettype($aAddOnOptions) . '" given');
     }
     $sMarkup = '';
     $sAddonTagName = 'span';
     $sAddonClass = '';
     if (!empty($aAddOnOptions['text'])) {
         if (!is_scalar($aAddOnOptions['text'])) {
             throw new \LogicException('"text" option expects a scalar value, "' . gettype($aAddOnOptions['text']) . '" given');
         } elseif ($oTranslator = $this->getTranslator()) {
             $sMarkup .= $oTranslator->translate($aAddOnOptions['text'], $this->getTranslatorTextDomain());
         } else {
             $sMarkup .= $aAddOnOptions['text'];
         }
         $sAddonClass .= ' input-group-addon';
     } elseif (!empty($aAddOnOptions['element'])) {
         if (is_array($aAddOnOptions['element']) || $aAddOnOptions['element'] instanceof \Traversable && !$aAddOnOptions['element'] instanceof \Zend\Form\ElementInterface) {
             $oFactory = new \Zend\Form\Factory();
             $aAddOnOptions['element'] = $oFactory->create($aAddOnOptions['element']);
         } elseif (!$aAddOnOptions['element'] instanceof \Zend\Form\ElementInterface) {
             throw new \LogicException(sprintf('"element" option expects an instanceof \\Zend\\Form\\ElementInterface, "%s" given', is_object($aAddOnOptions['element']) ? get_class($aAddOnOptions['element']) : gettype($aAddOnOptions['element'])));
         }
         $aAddOnOptions['element']->setOptions(array_merge($aAddOnOptions['element']->getOptions(), array('disable-twb' => true)));
         $sMarkup .= $this->render($aAddOnOptions['element']);
         if ($aAddOnOptions['element'] instanceof \Zend\Form\Element\Button) {
             $sAddonClass .= ' input-group-btn';
             //Element contains dropdown, so add-on container must be a "div"
             if ($aAddOnOptions['element']->getOption('dropdown')) {
                 $sAddonTagName = 'div';
             }
         } else {
             $sAddonClass .= ' input-group-addon';
         }
     }
     return sprintf(self::$addonFormat, $sAddonTagName, trim($sAddonClass), $sMarkup, $sAddonTagName);
 }
 /**
  *
  * @param array $formConfig
  * @return \Zend\Form\Factory
  */
 protected function createFormFromConfig(array $formConfig)
 {
     $Ofactory = new \Zend\Form\Factory();
     $form = $Ofactory->create($formConfig);
     $form->setAttribute("class", "form-horizontal");
     $form->setAttribute("id", "crud");
     /*if($this->getFrmFilterCrud() instanceof \Zend\InputFilter\InputFilterInterface){
           $form->setInputFilter($this->getFrmFilterCrud());
       }*/
     $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Save', 'id' => 'submitbutton')));
     $form->add(array('name' => 'cancel', 'attributes' => array('type' => 'button', 'value' => 'Cancel', 'id' => 'cancelbutton')));
     return $form;
 }
Beispiel #4
0
<?php

require_once './autoloader.php';
$config = array('name' => 'codeType', 'attributes' => array('type' => 'radio', 'label' => 'Code Type', 'options' => array('Markdown' => 'markdown', 'HTML' => 'html', 'Wiki' => 'wiki'), 'value' => array('markdown')));
$factory = new Zend\Form\Factory();
$element = $factory->create($config);
$helper = new Zend\Form\View\Helper\FormMultiCheckbox();
echo $helper->render($element);