true, 'action' => true, 'autocomplete' => true, 'enctype' => true, 'method' => true, 'name' => true, 'novalidate' => true, 'target' => true, ); /** * Invoke as function * * @param null|FormInterface $form * @return Form|string */ public function __invoke(FormInterface $form = null) { if (!$form) { return $this; } return $this->render($form); } /** * Render a form from the provided $form, * * @param FormInterface $form * @return string */ public function render(FormInterface $form) { if (method_exists($form, 'prepare')) { $form->prepare(); } $formContent = ''; foreach ($form as $element) { if ($element instanceof FieldsetInterface) { $formContent.= $this->getView()->formCollection($element); } else { $formContent.= $this->getView()->formRow($element); } } return $this->openTag($form) . $formContent . $this->closeTag(); } /** * Generate an opening form tag * * @param null|FormInterface $form * @return string */ public function openTag(FormInterface $form = null) { $doctype = $this->getDoctype(); $attributes = array(); if (! (Doctype::HTML5 === $doctype || Doctype::XHTML5 === $doctype)) { $attributes = array( 'action' => '', 'method' => 'get', ); } if ($form instanceof FormInterface) { $formAttributes = $form->getAttributes(); if (!array_key_exists('id', $formAttributes) && array_key_exists('name', $formAttributes)) { $formAttributes['id'] = $formAttributes['name']; } $attributes = array_merge($attributes, $formAttributes); } if ($attributes) { return sprintf('
', $this->createAttributesString($attributes)); } return ''; } /** * Generate a closing form tag * * @return string */ public function closeTag() { return '
'; } }