diff options
Diffstat (limited to 'inc/Form/Form.php')
-rw-r--r-- | inc/Form/Form.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/inc/Form/Form.php b/inc/Form/Form.php index 738f2bcf8..73b5b9cb3 100644 --- a/inc/Form/Form.php +++ b/inc/Form/Form.php @@ -258,6 +258,41 @@ class Form extends Element { } /** + * Adds a label referencing another input element, escapes the label for you + * + * @param $label + * @param string $for + * @param int $pos + * @return Element + */ + public function addLabel($label, $for='', $pos = -1) { + return $this->addLabelHTML(hsc($label), $for, $pos); + } + + /** + * Adds a label referencing another input element, allows HTML for content + * + * @param string $content + * @param string|Element $for + * @param int $pos + * @return Element + */ + public function addLabelHTML($content, $for='', $pos = -1) { + $element = new LabelElement(hsc($content)); + + if(is_a($for, '\dokuwiki\Form\Element')) { + /** @var Element $for */ + $for = $for->id(); + } + $for = (string) $for; + if($for !== '') { + $element->attr('for', $for); + } + + return $this->addElement($element, $pos); + } + + /** * Add fixed HTML to the form * * @param $html |