summaryrefslogtreecommitdiff
path: root/inc/Form/Form.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2015-08-18 20:36:08 +0200
committerAndreas Gohr <andi@splitbrain.org>2015-08-18 20:38:33 +0200
commita453c16b3290eabdf35778c54498101c737544e1 (patch)
treec3638bb285b3005758df58e81e7b148ea373523e /inc/Form/Form.php
parent8f0df229ed3e82191f118594ea5145c9d5942d7b (diff)
downloadrpg-a453c16b3290eabdf35778c54498101c737544e1.tar.gz
rpg-a453c16b3290eabdf35778c54498101c737544e1.tar.bz2
Form: more flexible label handling #1312
You now can add labels that don't wrap around inputs, but you have to ensure IDs are properly assigned yourself. The Label class has been renamed to LabelElement to reflect the naming scheme of the other elements.
Diffstat (limited to 'inc/Form/Form.php')
-rw-r--r--inc/Form/Form.php35
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