Source for file WTextArea.class.php

Documentation is available at WTextArea.class.php

  1. <?php
  2. /**
  3. * @since Jul 21, 2005
  4. * @package polyphony.wizard.components
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: WTextArea.class.php,v 1.12 2007/09/19 14:04:51 adamfranco Exp $
  10. */
  11.  
  12. require_once(dirname(__FILE__).'/WTextInput.abstract.php');
  13.  
  14. /**
  15. * This class allows for the creation of a textarea element
  16. *
  17. * @since Jul 21, 2005
  18. * @package polyphony.wizard.components
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: WTextArea.class.php,v 1.12 2007/09/19 14:04:51 adamfranco Exp $
  24. */
  25. class WTextArea
  26. extends WTextInput
  27. {
  28.  
  29. var $_rows;
  30. var $_cols;
  31. /**
  32. * Virtual Constructor
  33. * @param integer $rows
  34. * @param integer $cols
  35. * @access public
  36. * @return ref object
  37. * @static
  38. */
  39. static function withRowsAndColumns ($rows, $cols, $class = 'WTextArea') {
  40. $obj = new $class();
  41. $obj->setRows($rows);
  42. $obj->setColumns($cols);
  43. return $obj;
  44. }
  45. /**
  46. * Constructor
  47. * @access public
  48. * @return WTextArea
  49. */
  50. function __construct () {
  51. $this->_value = '';
  52. $this->_rows = 3;
  53. $this->_cols = 60;
  54. }
  55. /**
  56. * Sets the number of visible rows in this textarea.
  57. * @param integer $rows
  58. * @access public
  59. * @return void
  60. */
  61. function setRows ($rows) {
  62. ArgumentValidator::validate($rows, IntegerValidatorRule::getRule());
  63. $this->_rows = $rows;
  64. }
  65. /**
  66. * Sets the number of visible columns in this textarea.
  67. * @param integer $cols
  68. * @access public
  69. * @return void
  70. */
  71. function setColumns ($cols) {
  72. ArgumentValidator::validate($cols, IntegerValidatorRule::getRule());
  73. $this->_cols = $cols;
  74. }
  75. /**
  76. * Sets the size of this text area. This method allows Text-Areas to be used
  77. * more interchangebly with text-fields
  78. * @param int $size
  79. * @access public
  80. * @return void
  81. */
  82. function setSize ($size) {
  83. $this->setColumns($size);
  84. }
  85. /**
  86. * Returns a block of XHTML-valid code that contains markup for this specific
  87. * component.
  88. * @param string $fieldName The field name to use when outputting form data or
  89. * similar parameters/information.
  90. * @access public
  91. * @return string
  92. */
  93. function getMarkup ($fieldName) {
  94. $name = RequestContext::name($fieldName);
  95. $m = "\n\t\t\t<textarea rows='".$this->_rows."' cols='".$this->_cols."'";
  96. $m .= "\n\t\t\t\tname='$name'";
  97. $m .= (!$this->isEnabled()?" readonly='readonly'":"");
  98. if ($this->_style) {
  99. $m .= "\n\t\t\t\tstyle=\"".str_replace("\"", "\\\"", $this->_style)."\"";
  100. }
  101. if ($this->_onchange) {
  102. $m .= "\n\t\t\t\tonchange=\"".str_replace("\"", "\\\"", $this->_onchange)."\"";
  103. }
  104. if ($this->_value != null && $this->_value != $this->_startingDisplay) {
  105. $m .= ">".htmlspecialchars($this->_value);
  106. } else if ($this->_startingDisplay) {
  107. $v = htmlspecialchars($this->_startingDisplay, ENT_QUOTES);
  108. $m .= "\n\t\t\t\tonfocus='if (this.value == \"$v\") { this.value=\"\"; this.style.color=\"#000\";}'";
  109. $m .= "\n\t\t\t\tonblur='if (this.value == \"\") { this.value=\"$v\"; this.style.color=\"#888\";}'";
  110. $m .= " style='color: #888'>".$v;
  111. } else {
  112. $m .= ">".htmlspecialchars($this->_value);;
  113. }
  114. $m .= "</textarea>";
  115. $errText = $this->getErrorText();
  116. $errRule =$this->getErrorRule();
  117. $errStyle = $this->getErrorStyle();
  118. if ($errText && $errRule) {
  119. $m .= "<span id='".$fieldName."_error' style=\"padding-left: 10px; $errStyle\">&laquo; $errText</span>";
  120. $m .= Wizard::getValidationJavascript($fieldName, $errRule, $fieldName."_error", $this->_showError);
  121. $this->_showError = false;
  122. }
  123. return $m;
  124. }
  125. }
  126.  
  127. ?>

Documentation generated on Wed, 19 Sep 2007 10:28:23 -0400 by phpDocumentor 1.3.0RC3