xbutton.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Class for HTML 4.0 <button> element
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category HTML
  15. * @package HTML_QuickForm
  16. * @author Alexey Borzov <avb@php.net>
  17. * @copyright 2001-2009 The PHP Group
  18. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  19. * @version CVS: $Id: xbutton.php,v 1.3 2009/04/04 21:34:04 avb Exp $
  20. * @link http://pear.php.net/package/HTML_QuickForm
  21. */
  22. /**
  23. * Base class for form elements
  24. */
  25. require_once 'HTML/QuickForm/element.php';
  26. /**
  27. * Class for HTML 4.0 <button> element
  28. *
  29. * @category HTML
  30. * @package HTML_QuickForm
  31. * @author Alexey Borzov <avb@php.net>
  32. * @version Release: 3.2.11
  33. * @since 3.2.3
  34. */
  35. class HTML_QuickForm_xbutton extends HTML_QuickForm_element
  36. {
  37. /**
  38. * Contents of the <button> tag
  39. * @var string
  40. * @access private
  41. */
  42. var $_content;
  43. /**
  44. * Class constructor
  45. *
  46. * @param string Button name
  47. * @param string Button content (HTML to add between <button></button> tags)
  48. * @param mixed Either a typical HTML attribute string or an associative array
  49. * @access public
  50. */
  51. function HTML_QuickForm_xbutton($elementName = null, $elementContent = null, $attributes = null)
  52. {
  53. $this->HTML_QuickForm_element($elementName, null, $attributes);
  54. $this->setContent($elementContent);
  55. $this->setPersistantFreeze(false);
  56. $this->_type = 'xbutton';
  57. }
  58. function toHtml()
  59. {
  60. return '<button' . $this->getAttributes(true) . '>' . $this->_content . '</button>';
  61. }
  62. function getFrozenHtml()
  63. {
  64. return $this->toHtml();
  65. }
  66. function freeze()
  67. {
  68. return false;
  69. }
  70. function setName($name)
  71. {
  72. $this->updateAttributes(array(
  73. 'name' => $name
  74. ));
  75. }
  76. function getName()
  77. {
  78. return $this->getAttribute('name');
  79. }
  80. function setValue($value)
  81. {
  82. $this->updateAttributes(array(
  83. 'value' => $value
  84. ));
  85. }
  86. function getValue()
  87. {
  88. return $this->getAttribute('value');
  89. }
  90. /**
  91. * Sets the contents of the button element
  92. *
  93. * @param string Button content (HTML to add between <button></button> tags)
  94. */
  95. function setContent($content)
  96. {
  97. $this->_content = $content;
  98. }
  99. function onQuickFormEvent($event, $arg, &$caller)
  100. {
  101. if ('updateValue' != $event) {
  102. return parent::onQuickFormEvent($event, $arg, $caller);
  103. } else {
  104. $value = $this->_findValue($caller->_constantValues);
  105. if (null === $value) {
  106. $value = $this->_findValue($caller->_defaultValues);
  107. }
  108. if (null !== $value) {
  109. $this->setValue($value);
  110. }
  111. }
  112. return true;
  113. }
  114. /**
  115. * Returns a 'safe' element's value
  116. *
  117. * The value is only returned if the button's type is "submit" and if this
  118. * particlular button was clicked
  119. */
  120. function exportValue(&$submitValues, $assoc = false)
  121. {
  122. if ('submit' == $this->getAttribute('type')) {
  123. return $this->_prepareValue($this->_findValue($submitValues), $assoc);
  124. } else {
  125. return null;
  126. }
  127. }
  128. }
  129. ?>