xbutton.php 3.9 KB

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