xref: /dokuwiki/inc/Form/TextareaElement.php (revision 8c7c53b0321a3cd3116b8d3b2ad27863a38dece7)
112a4e4d1SAndreas Gohr<?php
2*9d01c1d9SSatoshi Sahara
312a4e4d1SAndreas Gohrnamespace dokuwiki\Form;
412a4e4d1SAndreas Gohr
512a4e4d1SAndreas Gohr/**
612a4e4d1SAndreas Gohr * Class TextareaElement
712a4e4d1SAndreas Gohr * @package dokuwiki\Form
812a4e4d1SAndreas Gohr */
9*9d01c1d9SSatoshi Saharaclass TextareaElement extends InputElement
10*9d01c1d9SSatoshi 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     */
20*9d01c1d9SSatoshi Sahara    public function __construct($name, $label)
21*9d01c1d9SSatoshi 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     */
34*9d01c1d9SSatoshi Sahara    public function val($value = null)
35*9d01c1d9SSatoshi 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     */
48*9d01c1d9SSatoshi Sahara    protected function mainElementHTML()
49*9d01c1d9SSatoshi Sahara    {
5012a4e4d1SAndreas Gohr        if ($this->useInput) $this->prefillInput();
5112a4e4d1SAndreas Gohr        return '<textarea ' . buildAttributes($this->attrs()) . '>' .
5212a4e4d1SAndreas Gohr            formText($this->val()) . '</textarea>';
5312a4e4d1SAndreas Gohr    }
5412a4e4d1SAndreas Gohr}
55