diff options
author | Guy Brand <gb@unistra.fr> | 2015-08-23 15:54:03 +0200 |
---|---|---|
committer | Guy Brand <gb@unistra.fr> | 2015-08-23 15:54:03 +0200 |
commit | d1c5a21205ecdf83c4cbdcd9245556121688e798 (patch) | |
tree | f99aacf8e4e2aad00b106d9b905a14c3536ba935 /inc/Form/Form.php | |
parent | 2beabe635c6b98fcf412ba42d137a5de33543109 (diff) | |
parent | 0f0d29909c63f9897c9c003e6d3e3b8381a6f36d (diff) | |
download | rpg-d1c5a21205ecdf83c4cbdcd9245556121688e798.tar.gz rpg-d1c5a21205ecdf83c4cbdcd9245556121688e798.tar.bz2 |
Merge branch 'master' into stable
Diffstat (limited to 'inc/Form/Form.php')
-rw-r--r-- | inc/Form/Form.php | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/inc/Form/Form.php b/inc/Form/Form.php index 625557fa1..7eaa53041 100644 --- a/inc/Form/Form.php +++ b/inc/Form/Form.php @@ -140,7 +140,7 @@ class Form extends Element { * @return Element */ public function addElement(Element $element, $pos = -1) { - if(is_a($element, '\dokuwiki\Form')) throw new \InvalidArgumentException('You can\'t add a form to a form'); + if(is_a($element, '\dokuwiki\Form\Form')) throw new \InvalidArgumentException('You can\'t add a form to a form'); if($pos < 0) { $this->elements[] = $element; } else { @@ -156,7 +156,7 @@ class Form extends Element { * @param $pos 0-based position of the element to replace */ public function replaceElement(Element $element, $pos) { - if(is_a($element, '\dokuwiki\Form')) throw new \InvalidArgumentException('You can\'t add a form to a form'); + if(is_a($element, '\dokuwiki\Form\Form')) throw new \InvalidArgumentException('You can\'t add a form to a form'); array_splice($this->elements, $pos, 1, array($element)); } @@ -234,6 +234,65 @@ class Form extends Element { } /** + * Adds a simple button, escapes the content for you + * + * @param string $name + * @param string $content + * @param int $pos + * @return Element + */ + public function addButton($name, $content, $pos = -1) { + return $this->addElement(new ButtonElement($name, hsc($content)), $pos); + } + + /** + * Adds a simple button, allows HTML for content + * + * @param string $name + * @param string $html + * @param int $pos + * @return Element + */ + public function addButtonHTML($name, $html, $pos = -1) { + return $this->addElement(new ButtonElement($name, $html), $pos); + } + + /** + * 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 |