/** * {@inheritDoc} */ public function getForm() { $currentStep = $this->getCurrentStep(); if (!$currentStep) { return; } if (null === $this->form) { $this->form = $this->formFactory->create(); $this->form->setAttribute('action', sprintf('?%s=%s', $this->getOptions()->getTokenParamName(), $this->getUniqueId())); if (!$this->getSteps()->getPrevious($currentStep)) { $this->form->remove('previous'); } if (!$this->getSteps()->getNext($currentStep)) { $this->form->remove('next'); } else { $this->form->remove('valid'); } } $stepForm = $currentStep->getForm(); if ($stepForm instanceof Form) { if ($this->form->has(self::STEP_FORM_NAME)) { $this->form->remove(self::STEP_FORM_NAME); } $stepForm->setName(self::STEP_FORM_NAME); $stepForm->populateValues($currentStep->getData()); $this->form->add($stepForm); } return $this->form; }
public function testCanAddFieldsetsUsingSpecs() { $this->form->add(array('type' => 'Zend\\Form\\Fieldset', 'name' => 'foo', 'attributes' => array('type' => 'fieldset', 'class' => 'foo-class', 'data-js-type' => 'my.form.fieldset'))); $this->assertTrue($this->form->has('foo')); $fieldset = $this->form->get('foo'); $this->assertInstanceOf('Zend\\Form\\FieldsetInterface', $fieldset); $this->assertEquals('foo', $fieldset->getName()); $this->assertEquals('fieldset', $fieldset->getAttribute('type')); $this->assertEquals('foo-class', $fieldset->getAttribute('class')); $this->assertEquals('my.form.fieldset', $fieldset->getAttribute('data-js-type')); }
public function testAddRemove() { $form = clone $this->form; $this->assertEquals($form, $this->form); $file = new Element\File('file_resource'); $this->form->add($file); $this->assertTrue($this->form->has('file_resource')); $this->assertNotEquals($form, $this->form); $this->form->remove('file_resource'); $this->assertEquals($form, $this->form); }
/** * @param Form $form * @param array $fields * @param array $overwrite * * @return string */ public function __invoke($form, $fields, $overwrite = null) { if ($overwrite === null) { $overwrite = array(); } if (!is_array($fields)) { $fields = array($fields); } $html = ''; foreach ($fields as $i => $field) { $addon = ''; if (!is_int($i)) { $addon = $field; $field = $i; } if (!$form->has($field)) { throw new \Exception(sprintf('Element doesn\'t exists \'%s\'', $field)); } $element = $form->get($field); $type = strtolower($element->getAttribute('type')); if (array_key_exists($field, $overwrite)) { if ($type === 'submit') { $element->setValue($overwrite[$field]); } else { $element->setOption('label', $overwrite[$field]); } } $plugin = $this->getPlugin($type); $prefix = ''; $encaps = '%s'; switch ($type) { case 'checkbox': $encaps = sprintf("<div class=\"checkbox-block\">%s</div><div class=\"col-xs-10\">%s</div>", '%s', $this->getLabel($element)); break; case "textarea": if (preg_match('/readonly/i', $element->getAttribute('class'))) { $prefix = '<p class="toggle-edit"><a href="#">Edit</a></p><iframe style="width:200px; height:100px; display: none;"></iframe>'; } default: $prefix .= $this->getLabel($element); break; } $input = $plugin($element); if (!empty($prefix)) { $prefix = sprintf($this->labelBlock, $prefix); } $html .= sprintf($this->format, $element->getName(), $prefix, sprintf($encaps, $input), $addon, $this->buildErrorMessage($element)); } return $html; }
/** * {@inheritDoc} */ public function remove($elementOrFieldset) { if (!parent::has($elementOrFieldset)) { if ($elementOrFieldset === 'captcha') { $elementOrFieldset = $this->getCaptchaElementName(); } elseif ($elementOrFieldset === 'csrf') { $elementOrFieldset = $this->getCsrfElementName(); } } return parent::remove($elementOrFieldset); }