Form.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @version $Id$
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /** Zend_View_Helper_FormElement */
  23. require_once 'Zend/View/Helper/FormElement.php';
  24. /**
  25. * Helper for rendering HTML forms
  26. *
  27. * @package Zend_View
  28. * @subpackage Helper
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_View_Helper_Form extends Zend_View_Helper_FormElement
  33. {
  34. /**
  35. * Render HTML form
  36. *
  37. * @param string $name Form name
  38. * @param null|array $attribs HTML form attributes
  39. * @param false|string $content Form content
  40. * @return string
  41. */
  42. public function form($name, $attribs = null, $content = false)
  43. {
  44. $info = $this->_getInfo($name, $content, $attribs);
  45. extract($info);
  46. if (!empty($id)) {
  47. $id = ' id="' . $this->view->escape($id) . '"';
  48. } else {
  49. $id = '';
  50. }
  51. if (array_key_exists('id', $attribs) && empty($attribs['id'])) {
  52. unset($attribs['id']);
  53. }
  54. if (!empty($name) && !($this->_isXhtml() && $this->_isStrictDoctype())) {
  55. $name = ' name="' . $this->view->escape($name) . '"';
  56. } else {
  57. $name = '';
  58. }
  59. if ($this->_isHtml5() && array_key_exists('action', $attribs) && !$attribs['action']) {
  60. unset($attribs['action']);
  61. }
  62. if ( array_key_exists('name', $attribs) && empty($attribs['id'])) {
  63. unset($attribs['id']);
  64. }
  65. $xhtml = '<form'
  66. . $id
  67. . $name
  68. . $this->_htmlAttribs($attribs)
  69. . '>';
  70. if (false !== $content) {
  71. $xhtml .= $content
  72. . '</form>';
  73. }
  74. return $xhtml;
  75. }
  76. }