112a4e4d1SAndreas Gohr<?php 29d01c1d9SSatoshi Sahara 312a4e4d1SAndreas Gohrnamespace dokuwiki\Form; 412a4e4d1SAndreas Gohr 512a4e4d1SAndreas Gohr/** 612a4e4d1SAndreas Gohr * Class TextareaElement 712a4e4d1SAndreas Gohr * @package dokuwiki\Form 812a4e4d1SAndreas Gohr */ 99d01c1d9SSatoshi Saharaclass TextareaElement extends InputElement 109d01c1d9SSatoshi Sahara{ 1112a4e4d1SAndreas Gohr /** 1212a4e4d1SAndreas Gohr * @var string the actual text within the area 1312a4e4d1SAndreas Gohr */ 1412a4e4d1SAndreas Gohr protected $text; 1512a4e4d1SAndreas Gohr 1612a4e4d1SAndreas Gohr /** 1712a4e4d1SAndreas Gohr * @param string $name The name of this form element 1812a4e4d1SAndreas Gohr * @param string $label The label text for this element 1912a4e4d1SAndreas Gohr */ 209d01c1d9SSatoshi Sahara public function __construct($name, $label) 219d01c1d9SSatoshi Sahara { 2212a4e4d1SAndreas Gohr parent::__construct('textarea', $name, $label); 23de19515fSAndreas Gohr $this->attr('dir', 'auto'); 2412a4e4d1SAndreas Gohr } 2512a4e4d1SAndreas Gohr 2612a4e4d1SAndreas Gohr /** 2712a4e4d1SAndreas Gohr * Get or set the element's value 2812a4e4d1SAndreas Gohr * 2912a4e4d1SAndreas Gohr * This is the preferred way of setting the element's value 3012a4e4d1SAndreas Gohr * 3112a4e4d1SAndreas Gohr * @param null|string $value 3212a4e4d1SAndreas Gohr * @return string|$this 3312a4e4d1SAndreas Gohr */ 349d01c1d9SSatoshi Sahara public function val($value = null) 359d01c1d9SSatoshi Sahara { 3612a4e4d1SAndreas Gohr if ($value !== null) { 376834946fSAndreas Gohr $this->text = cleanText($value); 3812a4e4d1SAndreas Gohr return $this; 3912a4e4d1SAndreas Gohr } 4012a4e4d1SAndreas Gohr return $this->text; 4112a4e4d1SAndreas Gohr } 4212a4e4d1SAndreas Gohr 4312a4e4d1SAndreas Gohr /** 4412a4e4d1SAndreas Gohr * The HTML representation of this element 4512a4e4d1SAndreas Gohr * 4612a4e4d1SAndreas Gohr * @return string 4712a4e4d1SAndreas Gohr */ 489d01c1d9SSatoshi Sahara protected function mainElementHTML() 499d01c1d9SSatoshi Sahara { 5012a4e4d1SAndreas Gohr if ($this->useInput) $this->prefillInput(); 51*39904235SAndreas Gohr // The browser's HTML parser ignores a single newline immediately 52*39904235SAndreas Gohr // after a <textarea> start tag, so a value that itself begins with a 53*39904235SAndreas Gohr // newline would lose it on round-trip. We emit a guard newline that 54*39904235SAndreas Gohr // absorbs the one the browser drops, keeping the value intact. 55*39904235SAndreas Gohr // See the HTML Standard, "in body" insertion mode (the LF right after 56*39904235SAndreas Gohr // <textarea> is dropped as an authoring convenience): 57*39904235SAndreas Gohr // https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody 58*39904235SAndreas Gohr return '<textarea ' . buildAttributes($this->attrs()) . '>' . "\n" . 5912a4e4d1SAndreas Gohr formText($this->val()) . '</textarea>'; 6012a4e4d1SAndreas Gohr } 6112a4e4d1SAndreas Gohr} 62