public function __invoke(FormInterface $form = null) { if ($form) { if ($form->getOption('form-inline') || $this->hasClass($form, 'form-inline')) { $form = $this->addClass($form, 'form-inline'); foreach ($form as $element) { $element->setOption('form-inline', true); } } elseif ($form->getOption('form-horizontal') || $this->hasClass($form, 'form-hotizontal')) { $form = $this->addClass($form, 'form-horizontal'); $labelCols = (int) $form->getOption('label-cols') ?: 3; $inputCols = (int) $form->getOption('input-cols') ?: 12 - $labelCols; foreach ($form as $element) { $options = array_merge($element->getOptions(), ['form-horizontal' => true, 'label-cols' => $labelCols, 'input-cols' => $inputCols]); $element->setOptions($options); } } } $markup = parent::__invoke($form); //dump($markup); return $markup; }
/** * Generate an opening form tag * @param null|FormInterface $form * @return string */ public function openTag(FormInterface $form = null) { $this->setFormClass($form, $this->formLayout); return parent::openTag($form); }
/** * Generate an opening form tag * @param null|FormInterface $form * @param null|string $formType * @param array $displayOptions * @throws \DluTwBootstrap\Form\Exception\UnsupportedFormTypeException * @return string */ public function openTag(FormInterface $form = null, $formType = null, $displayOptions = array()) { $formType = $this->formUtil->filterFormType($formType); if (!array_key_exists($formType, $this->formTypeMap)) { throw new UnsupportedFormTypeException("Unsupported form type '{$formType}'."); } if ($form) { $class = $this->genUtil->addWords($this->formTypeMap[$formType], $form->getAttribute('class')); if (array_key_exists('class', $displayOptions)) { $class = $this->genUtil->addWords($displayOptions['class'], $class); } $escapeHtmlAttrHelper = $this->getEscapeHtmlAttrHelper(); $class = $this->genUtil->escapeWords($class, $escapeHtmlAttrHelper); $form->setAttribute('class', $class); } return parent::openTag($form); }
/** * Set Form Helper * * @param \Zend\Form\View\Helper\Form $form * @return self */ public function setFormHelper(FormHelper $form) { $form->setView($this->getView()); $this->formHelper = $form; return $this; }
/** * @inheritdoc */ public function __construct($name = null, $options = array()) { parent::__construct($name, $options); $this->add(array('name' => 'title', 'type' => 'Text', 'options' => array('label' => '* Nome'), 'attributes' => array('required' => 'required', 'placeholder' => 'Titolo...', 'title' => 'Inserisci il titolo', 'id' => 'title'))); $this->add(array('type' => 'Zend\\Form\\Element\\Hidden', 'name' => 'id', 'attributes' => array("class" => 'hiddenField'))); }
} </script> </head> <body> <?php $file = new Element\File('file'); $file->setLabel('File'); $progress_key = new Element\Hidden('progress_key'); $progress_key->setAttribute('id', 'progress_key'); $progress_key->setValue(md5(uniqid(rand()))); $submit = new Element\Submit('submit'); $submit->setValue('Upload!'); $form = new Form("ZendForm"); $form->setAttributes(array('enctype' => 'multipart/form-data', 'action' => 'ZendForm.php', 'target' => 'uploadTarget', 'onsubmit' => 'observeProgress();')); $form->prepare(); $formhelper = new Helper\Form(); $formfile = new Helper\FormFile(); $formhidden = new Helper\FormHidden(); $formsubmit = new Helper\FormSubmit(); echo $formhelper->openTag($form); echo $formhidden($progress_key); echo $formfile($file); echo $formsubmit($submit); echo $formhelper->closeTag(); ?> <iframe name="uploadTarget"></iframe> <div id="progressbar"> <div class="pg-progressbar"> <div class="pg-progress" id="pg-percent"> <div class="pg-progressstyle"></div>
public function openTag(FormInterface $form = null, $isHorizontal = false) { $this->isHorizontal = (bool) $isHorizontal; $this->setHorizontal($form); return parent::openTag($form); }
/** * Close tag * * @return string */ public function closeTag() { $helper = new Helper\Form(); return $helper->closeTag(); }
/** * @param FormInterface $form * @return string */ public function render(FormInterface $form) { $this->detectBootstrapType($form); return parent::render($form); }
/** * {@inheritDoc} */ public function openTag(FormInterface $form = null) { if ($form) { $class = $form->getAttribute('class'); if (strpos($class, $this->defaultClass) === false) { $class = trim("{$class} {$this->defaultClass}"); } if ($object = $form->getObject()) { $className = str_replace(array_keys($this->classNameReplacements), array_values($this->classNameReplacements), get_class($object)); } else { $className = get_class($form); } $parts = explode('\\', $className); foreach ($parts as $part) { $classes[] = strtolower($part); if (count($classes) > 1) { $class .= ' ' . implode('-', $classes); } } $form->setAttribute('class', $class); $formAttributes = $form->getAttributes(); if (!array_key_exists('id', $formAttributes) && $classes) { $form->setAttribute('id', implode('-', $classes)); } } return parent::openTag($form); }
/** * Render a form from the provided $form, * * @param ElementInterface $element * @param null|bool|string|\Translator $translator * @param null|string $textDomain * @throws Exception\DomainException * @return string */ public function __invoke(FormInterface $form = null, $translator = null, $textDomain = null) { if (!empty($translator)) { if ($translator instanceof Translator) { $this->setTranslator($translator); if (!empty($textDomain)) { $this->setTranslatorTextDomain((string) $textDomain); } } else { if (is_bool($translator)) { $this->setTranslatorEnabled($translator); } else { $this->setTranslatorTextDomain((string) $translator); } } } return parent::__invoke($form); }