TextareaElement.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace dokuwiki\Form;
  3. /**
  4. * Class TextareaElement
  5. * @package dokuwiki\Form
  6. */
  7. class TextareaElement extends InputElement
  8. {
  9. /**
  10. * @var string the actual text within the area
  11. */
  12. protected $text;
  13. /**
  14. * @param string $name The name of this form element
  15. * @param string $label The label text for this element
  16. */
  17. public function __construct($name, $label)
  18. {
  19. parent::__construct('textarea', $name, $label);
  20. $this->attr('dir', 'auto');
  21. }
  22. /**
  23. * Get or set the element's value
  24. *
  25. * This is the preferred way of setting the element's value
  26. *
  27. * @param null|string $value
  28. * @return string|$this
  29. */
  30. public function val($value = null)
  31. {
  32. if ($value !== null) {
  33. $this->text = cleanText($value);
  34. return $this;
  35. }
  36. return $this->text;
  37. }
  38. /**
  39. * The HTML representation of this element
  40. *
  41. * @return string
  42. */
  43. protected function mainElementHTML()
  44. {
  45. if ($this->useInput) $this->prefillInput();
  46. return '<textarea ' . buildAttributes($this->attrs()) . '>' .
  47. formText($this->val()) . '</textarea>';
  48. }
  49. }