attr('action')) { $get = $_GET; if(isset($get['id'])) unset($get['id']); $self = wl($ID, $get, false, '&'); //attributes are escaped later $this->attr('action', $self); } // post is default if(!$this->attr('method')) { $this->attr('method', 'post'); } // we like UTF-8 if(!$this->attr('accept-charset')) { $this->attr('accept-charset', 'utf-8'); } // add the security token by default $this->setHiddenField('sectok', getSecurityToken()); // identify this as a new form based form in HTML $this->addClass('doku_form'); } /** * Sets a hidden field * * @param $name * @param $value * @return $this */ public function setHiddenField($name, $value) { $this->hidden[$name] = $value; return $this; } #region Element adding functions /** * Adds an element to the end of the form * * @param Element $element * @param int $pos 0-based position in the form, -1 for at the end * @return Element */ public function addElement(Element $element, $pos = -1) { if(is_a($element, 'Doku_Form2')) throw new \InvalidArgumentException('You can\'t add a form to a form'); if($pos < 0) { $this->elements[] = $element; } else { array_splice($this->elements, $pos, 0, array($element)); } return $element; } /** * Adds a text input field * * @param $name * @param $label * @param int $pos * @return InputElement */ public function addTextInput($name, $label = '', $pos = -1) { return $this->addElement(new InputElement('text', $name, $label), $pos); } /** * Adds a password input field * * @param $name * @param $label * @param int $pos * @return InputElement */ public function addPasswordInput($name, $label = '', $pos = -1) { return $this->addElement(new InputElement('password', $name, $label), $pos); } /** * Adds a radio button field * * @param $name * @param $label * @param int $pos * @return CheckableElement */ public function addRadioButton($name, $label = '', $pos = -1) { return $this->addElement(new CheckableElement('radio', $name, $label), $pos); } /** * Adds a checkbox field * * @param $name * @param $label * @param int $pos * @return CheckableElement */ public function addCheckbox($name, $label = '', $pos = -1) { return $this->addElement(new CheckableElement('checkbox', $name, $label), $pos); } /** * Adds a textarea field * * @param $name * @param $label * @param int $pos * @return TextareaElement */ public function addTextarea($name, $label = '', $pos = -1) { return $this->addElement(new TextareaElement($name, $label), $pos); } /** * Add fixed HTML to the form * * @param $html * @param int $pos * @return HTMLElement */ public function addHTML($html, $pos = -1) { return $this->addElement(new HTMLElement($html), $pos); } /** * Add a closed HTML tag to the form * * @param $tag * @param int $pos * @return TagElement */ public function addTag($tag, $pos = -1) { return $this->addElement(new TagElement($tag), $pos); } /** * Add an open HTML tag to the form * * Be sure to close it again! * * @param $tag * @param int $pos * @return TagOpenElement */ public function addTagOpen($tag, $pos = -1) { return $this->addElement(new TagOpenElement($tag), $pos); } /** * Add a closing HTML tag to the form * * Be sure it had been opened before * * @param $tag * @param int $pos * @return TagCloseElement */ public function addTagClose($tag, $pos = -1) { return $this->addElement(new TagCloseElement($tag), $pos); } /** * Open a Fieldset * * @param $legend * @param int $pos * @return FieldsetOpenElement */ public function addFieldsetOpen($legend='', $pos = -1) { return $this->addElement(new FieldsetOpenElement($legend), $pos); } /** * Close a fieldset * * @param int $pos * @return TagCloseElement */ public function addFieldsetClose($pos = -1) { return $this->addElement(new FieldsetCloseElement(), $pos); } #endregion protected function balanceFieldsets() { //todo implement! } /** * The HTML representation of the whole form * * @return string */ public function toHTML() { $this->balanceFieldsets(); $html = '
attrs()) . '>' . DOKU_LF; foreach($this->hidden as $name => $value) { $html .= '' . DOKU_LF; } foreach($this->elements as $element) { $html .= $element->toHTML() . DOKU_LF; } $html .= '
' . DOKU_LF; return $html; } }