File modules/template_engine/components/html/component_form/FormComponent.class.php

Last commit: Tue Oct 13 18:47:47 2026 +0200	Jan Dankert	Fixing some template issues: Removed unused attributes. The XSD description for template elements contains now comments.
1 <?php 2 3 namespace template_engine\components\html\component_form; 4 5 use cms\action\RequestParams; 6 use language\Messages; 7 use template_engine\components\html\Component; 8 use template_engine\element\CMSElement; 9 use template_engine\element\HtmlElement; 10 use template_engine\element\Value; 11 use template_engine\element\ValueExpression; 12 13 /** 14 * Displays a HTML form. 15 */ 16 class FormComponent extends Component 17 { 18 /** 19 * HTTP method, must be POST or GET. 20 */ 21 public string $method = 'POST'; 22 23 /** 24 * The name attribute of the form 25 */ 26 public string $name = ''; 27 public string|null $action = null; 28 public string|null $subaction = null; 29 public $forwardTo = null; 30 31 public $id = '${_id}'; 32 33 public int|null $languageid = null; 34 public int|null $modelid = null; 35 36 public string $label = '${message:button_ok}'; 37 38 /** 39 * Adding an apply-button 40 */ 41 public bool $apply = false; 42 /** 43 * Adding a cancel button. 44 */ 45 public bool $cancel = true; 46 47 public bool $readonly = false; 48 49 /** 50 * 'view' = Loads Action in the same view 51 * 'top' = Replaces whole workbench. 52 * @var string 53 */ 54 public $target = 'view'; 55 56 public $enctype = 'application/x-www-form-urlencoded'; 57 58 public $async = false; 59 60 public $autosave = false; 61 62 public $type = ''; 63 64 public $afterSuccess; 65 66 private $token = '${_token}'; 67 68 69 public function createElement() 70 { 71 if ( ! $this->action ) 72 $this->action = $this->context->action; 73 74 if ( ! $this->subaction ) 75 $this->subaction = $this->context->subaction; 76 77 if ( ! $this->id ) 78 $this->id = $this->context->id; 79 80 $form = new CMSElement('form'); 81 82 #if ($this->type == 'upload') 83 # $this->submitFunction = ''; 84 85 $form->addAttribute('name', $this->name); 86 $form->addAttribute('target', '_self'); 87 $form->addAttribute('data-target', $this->target); 88 $form->addAttribute('action', './'); 89 if ( $this->forwardTo ) 90 $form->addAttribute('data-forward-to', $this->forwardTo); 91 $form->addAttribute('data-method', $this->subaction); 92 $form->addAttribute('data-action', $this->action); 93 $form->addAttribute('data-id', $this->id); 94 $form->addAttribute('method', $this->method); 95 $form->addAttribute('enctype', $this->enctype); 96 $form->addStyleClass('form')->addStyleClass($this->action); 97 $form->addAttribute('data-async', $this->async); 98 $form->addAttribute('data-autosave', $this->autosave); 99 100 if ($this->afterSuccess) 101 $form->addAttribute('data-after-success', $this->afterSuccess); 102 103 $form->addChild( 104 (new HtmlElement('div'))->addStyleClass('form-headline') 105 ); 106 107 // Creating the action bar 108 $actionBar = (new HtmlElement('div'))->addStyleClass('form-actionbar'); 109 110 if ( !$this->readonly && !$this->autosave ) { 111 // Show action buttons 112 113 if ($this->cancel) { 114 // Adding a cancel-button. 115 $actionBar->addChild( 116 (new CMSElement('div')) 117 ->addStyleClass('btn') 118 ->addStyleClass('btn--control') 119 ->addStyleClass('btn--secondary') 120 ->addStyleClass('act-form-cancel') 121 ->addChild( 122 (new HtmlElement('i'))->addStyleClass(['image-icon','image-icon--form-cancel']) 123 )->addChild( 124 (new HtmlElement('span'))->addStyleClass('form-btn-label')->content(Value::createExpression(ValueExpression::TYPE_MESSAGE, Messages::CANCEL)) 125 ) 126 ); 127 } 128 129 if ($this->apply) { 130 // Adding an apply-button 131 $actionBar->addChild( 132 (new CMSElement('div')) 133 ->addStyleClass('btn') 134 ->addStyleClass('btn--control') 135 ->addStyleClass('btn--primary') 136 ->addStyleClass('act-form-apply') 137 ->addChild( 138 (new HtmlElement('i'))->addStyleClass(['image-icon','image-icon--form-apply']) 139 )->addChild( 140 (new HtmlElement('span'))->addStyleClass('form-btn-label')->content(Value::createExpression(ValueExpression::TYPE_MESSAGE, Messages::APPLY)) 141 ) 142 ); 143 } 144 145 // Adding the save-button 146 $actionBar->addChild( 147 (new CMSElement('div')) 148 ->addStyleClass('btn') 149 ->addStyleClass('btn--control') 150 ->addStyleClass('btn--primary') 151 ->addStyleClass('act-form-save') 152 ->addChild( 153 (new HtmlElement('i'))->addStyleClass(['image-icon','image-icon--form-ok']) 154 )->addChild( 155 (new HtmlElement('span'))->addStyleClass('form-btn-label')->content($this->label) 156 ) 157 ); 158 } 159 160 $formContent = (new HtmlElement('div'))->addStyleClass('form-content')->asChildOf($form); 161 162 if ($this->languageid) 163 $formContent->addChild( 164 (new CMSElement('input')) 165 ->addAttribute('type', 'hidden') 166 ->addAttribute('name', RequestParams::PARAM_LANGUAGE_ID) 167 ->addAttribute('value', $this->languageid) 168 ); 169 170 if ($this->modelid) 171 $formContent->addChild( 172 (new CMSElement('input')) 173 ->addAttribute('type', 'hidden') 174 ->addAttribute('name', RequestParams::PARAM_MODEL_ID) 175 ->addAttribute('value', $this->modelid) 176 ); 177 178 $formContent->addChild( 179 (new CMSElement('input')) 180 ->addAttribute('type', 'hidden') 181 ->addAttribute('name', RequestParams::PARAM_TOKEN) 182 ->addAttribute('value', $this->token) 183 ); 184 185 $formContent->addChild( 186 (new CMSElement('input')) 187 ->addAttribute('type', 'hidden') 188 ->addAttribute('name', RequestParams::PARAM_ACTION) 189 ->addAttribute('value', $this->action) 190 ); 191 $formContent->addChild( 192 (new CMSElement('input')) 193 ->addAttribute('type', 'hidden') 194 ->addAttribute('name', RequestParams::PARAM_SUBACTION) 195 ->addAttribute('value', $this->subaction) 196 ); 197 $formContent->addChild( 198 (new CMSElement('input')) 199 ->addAttribute('type', 'hidden') 200 ->addAttribute('name', RequestParams::PARAM_ID) 201 ->addAttribute('value', $this->id) 202 ); 203 204 205 206 $this->adoptiveElement = $formContent; 207 208 $form->addChild( $actionBar ); 209 210 return $form; 211 } 212 }
Download modules/template_engine/components/html/component_form/FormComponent.class.php
History Tue, 13 Oct 2026 18:47:47 +0200 Jan Dankert Fixing some template issues: Removed unused attributes. The XSD description for template elements contains now comments. Tue, 13 Oct 2026 14:55:30 +0200 Jan Dankert The XSD Generator is now able to generate XSD annotations (mean: comments), this makes editing the templates much easier :) Sun, 8 Dec 2024 20:56:47 +0100 Jan Dankert New: Users are now able to store bookmarks. Wed, 17 Nov 2021 23:22:19 +0100 Jan Dankert Refactoring: Using a template context for templates instead of the HTTP-Request-Data Tue, 1 Dec 2020 00:07:39 +0100 Jan Dankert New: Visibility-Button for password fields, fix: QR-code button for mobile devices. Thu, 12 Nov 2020 01:12:45 +0100 Jan Dankert Fix: Workflow for changing the users email adress; Mail sending; Forwarding forms Wed, 14 Oct 2020 22:36:29 +0200 Jan Dankert Refactoring: Fixed the namespace in component classes, now the are able to be load by the standard autoloader. Wed, 14 Oct 2020 22:20:22 +0200 Jan Dankert Refactoring: Renamed component folders, because 'if' is no valid namespace fragment.