Source of file Form.php
Size: 2,744 Bytes - Last Modified: 2014-03-12T23:21:18+01:00
/home/theseer/Downloads/ZendFramework-2.3.0/library/Zend/Form/View/Helper/Form.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | <?php /** * Zend Framework (http://framework.zend.com/) * * @link http://github.com/zendframework/zf2 for the canonical source repository * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com) * @license http://framework.zend.com/license/new-bsd New BSD License */ namespace Zend\Form\View\Helper; use Zend\Form\FieldsetInterface; use Zend\Form\FormInterface; /** * View helper for rendering Form objects */ class Form extends AbstractHelper { /** * Attributes valid for this tag (form) * * @var array */ protected $validTagAttributes = array( 'accept-charset' => true, 'action' => true, 'autocomplete' => true, 'enctype' => true, 'method' => true, 'name' => true, 'novalidate' => true, 'target' => true, ); /** * Invoke as function * * @param null|FormInterface $form * @return Form */ 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) { $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); } $tag = sprintf('<form %s>', $this->createAttributesString($attributes)); return $tag; } /** * Generate a closing form tag * * @return string */ public function closeTag() { return '</form>'; } } |