ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTextInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
5include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
6include_once 'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
7include_once 'Services/Form/interfaces/interface.ilMultiValuesItem.php';
8
17{
18 protected $value;
19 protected $maxlength = 200;
20 protected $size = 40;
23 protected $suffix;
24 protected $style_css;
25 protected $css_class;
28 protected $ajax_datasource_commit = false;
30 protected $submit_form_on_enter = false;
31
35 protected $autocomplete_disabled = false;
36
43 public function __construct($a_title = "", $a_postvar = "")
44 {
45 global $DIC;
46
47 $this->lng = $DIC->language();
48 parent::__construct($a_title, $a_postvar);
49 $this->setInputType("text");
50 $this->setType("text");
51 $this->validationRegexp = "";
52 }
53
59 public function setValue($a_value)
60 {
61 if ($this->getMulti() && is_array($a_value)) {
62 $this->setMultiValues($a_value);
63 $a_value = array_shift($a_value);
64 }
65 $this->value = $a_value;
66 }
67
73 public function getValue()
74 {
75 return $this->value;
76 }
77
78
84 public function setValidationFailureMessage($a_msg)
85 {
86 $this->validationFailureMessage = $a_msg;
87 }
88
90 {
92 }
93
99 public function setValidationRegexp($a_value)
100 {
101 $this->validationRegexp = $a_value;
102 }
103
109 public function getValidationRegexp()
110 {
112 }
113
119 public function setMaxLength($a_maxlength)
120 {
121 $this->maxlength = $a_maxlength;
122 }
123
129 public function getMaxLength()
130 {
131 return $this->maxlength;
132 }
133
139 public function setSize($a_size)
140 {
141 $this->size = $a_size;
142 }
143
149 public function setInlineStyle($a_style)
150 {
151 $this->style_css = $a_style;
152 }
153
159 public function getInlineStyle()
160 {
161 return $this->style_css;
162 }
163
164 public function setCssClass($a_class)
165 {
166 $this->css_class = $a_class;
167 }
168
169 public function getCssClass()
170 {
171 return $this->css_class;
172 }
173
174
180 public function setValueByArray($a_values)
181 {
182 $this->setValue($a_values[$this->getPostVar()]);
183 }
184
190 public function getSize()
191 {
192 return $this->size;
193 }
194
200 public function setSuffix($a_value)
201 {
202 $this->suffix = $a_value;
203 }
204
210 public function getSuffix()
211 {
212 return $this->suffix;
213 }
214
222 public function setInputType($a_type)
223 {
224 $this->input_type = $a_type;
225 }
226
232 public function getInputType()
233 {
234 return $this->input_type;
235 }
236
242 public function setSubmitFormOnEnter($a_val)
243 {
244 $this->submit_form_on_enter = $a_val;
245 }
246
252 public function getSubmitFormOnEnter()
253 {
255 }
256
262 public function checkInput()
263 {
265
266 if (!$this->getMulti()) {
267 //$_POST[$this->getPostVar()] = ilUtil::stripSlashes($_POST[$this->getPostVar()]);
268 $_POST[$this->getPostVar()] = $this->stripSlashesAddSpaceFallback($_POST[$this->getPostVar()]);
269 if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") {
270 $this->setAlert($lng->txt("msg_input_is_required"));
271
272 return false;
273 } elseif (strlen($this->getValidationRegexp())) {
274 if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()])) {
275 $this->setAlert(
278 $lng->txt('msg_wrong_format')
279 );
280 return false;
281 }
282 }
283 } else {
284 // #17296
285 if (!is_array($_POST[$this->getPostVar()])) {
286 $_POST[$this->getPostVar()] = array();
287 }
288 foreach ($_POST[$this->getPostVar()] as $idx => $value) {
289 //$_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
290 $_POST[$this->getPostVar()][$idx] = $this->stripSlashesAddSpaceFallback($value);
291 }
292 $_POST[$this->getPostVar()] = array_unique($_POST[$this->getPostVar()]);
293
294 if ($this->getRequired() && !trim(implode("", $_POST[$this->getPostVar()]))) {
295 $this->setAlert($lng->txt("msg_input_is_required"));
296
297 return false;
298 } elseif (strlen($this->getValidationRegexp())) {
299 $reg_valid = true;
300 foreach ($_POST[$this->getPostVar()] as $value) {
301 if (!preg_match($this->getValidationRegexp(), $value)) {
302 $reg_valid = false;
303 break;
304 }
305 }
306 if (!$reg_valid) {
307 $this->setAlert(
310 $lng->txt('msg_wrong_format')
311 );
312 return false;
313 }
314 }
315 }
316
317 return $this->checkSubItemsInput();
318 }
319
324 public function getDataSource()
325 {
327 }
328
333 public function setDataSource($href, $a_delimiter = null)
334 {
335 $this->ajax_datasource = $href;
336 $this->ajax_datasource_delimiter = $a_delimiter;
337 }
338
339 public function setDataSourceSubmitOnSelection($a_stat)
340 {
341 $this->ajax_datasource_commit = $a_stat;
342 }
343
345 {
347 }
348
349 public function setDataSourceSubmitUrl($a_url)
350 {
351 $this->ajax_datasource_commit_url = $a_url;
352 }
353 public function getDataSourceSubmitUrl()
354 {
356 }
357
358
359 public function setMultiValues(array $a_values)
360 {
361 foreach ($a_values as $idx => $value) {
362 $a_values[$idx] = trim($value);
363 if ($a_values[$idx] == "") {
364 unset($a_values[$idx]);
365 }
366 }
367 parent::setMultiValues($a_values);
368 }
369
373 public function render($a_mode = "")
374 {
379
380 $tpl = new ilTemplate("tpl.prop_textinput.html", true, true, "Services/Form");
381 if (strlen($this->getValue())) {
382 $tpl->setCurrentBlock("prop_text_propval");
383 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
384 $tpl->parseCurrentBlock();
385 }
386 if (strlen($this->getInlineStyle())) {
387 $tpl->setCurrentBlock("stylecss");
388 $tpl->setVariable("CSS_STYLE", ilUtil::prepareFormOutput($this->getInlineStyle()));
389 $tpl->parseCurrentBlock();
390 }
391 if (strlen($this->getCssClass())) {
392 $tpl->setCurrentBlock("classcss");
393 $tpl->setVariable('CLASS_CSS', ilUtil::prepareFormOutput($this->getCssClass()));
394 $tpl->parseCurrentBlock();
395 }
396 if ($this->getSubmitFormOnEnter()) {
397 $tpl->touchBlock("submit_form_on_enter");
398 }
399
400 switch ($this->getInputType()) {
401 case 'password':
402 $tpl->setVariable('PROP_INPUT_TYPE', 'password');
403 break;
404 case 'hidden':
405 $tpl->setVariable('PROP_INPUT_TYPE', 'hidden');
406 break;
407 case 'text':
408 default:
409 $tpl->setVariable('PROP_INPUT_TYPE', 'text');
410 }
411 $tpl->setVariable("ID", $this->getFieldId());
412 $tpl->setVariable("SIZE", $this->getSize());
413 if ($this->getMaxLength() != null) {
414 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
415 }
416 if (strlen($this->getSuffix())) {
417 $tpl->setVariable("INPUT_SUFFIX", $this->getSuffix());
418 }
419
420 $postvar = $this->getPostVar();
421 if ($this->getMulti() && substr($postvar, -2) != "[]") {
422 $postvar .= "[]";
423 }
424
425 $tpl->setVariable("POST_VAR", $postvar);
426 if ($this->getDisabled()) {
427 if ($this->getMulti()) {
428 $value = $this->getMultiValues();
429 $hidden = "";
430 if (is_array($value)) {
431 foreach ($value as $item) {
432 $hidden .= $this->getHiddenTag($postvar, $item);
433 }
434 }
435 } else {
436 $hidden = $this->getHiddenTag($postvar, $this->getValue());
437 }
438 if ($hidden) {
439 $tpl->setVariable("HIDDEN_INPUT", $hidden);
440 }
441 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
442 }
443
444 // use autocomplete feature?
445 if ($this->getDataSource()) {
446 include_once "Services/jQuery/classes/class.iljQueryUtil.php";
449
450 if ($this->getMulti()) {
451 $tpl->setCurrentBlock("ac_multi");
452 $tpl->setVariable('MURL_AUTOCOMPLETE', $this->getDataSource());
453 $tpl->setVariable('ID_AUTOCOMPLETE', $this->getFieldId());
454 $tpl->parseCurrentBlock();
455
456 // set to fields that start with autocomplete selector
457 $sel_auto = '[id^="' . $this->getFieldId() . '"]';
458 } else {
459 // use id for autocomplete selector
460 $sel_auto = "#" . $this->getFieldId();
461 }
462
463 $tpl->setCurrentBlock("autocomplete_bl");
464 if (!$this->ajax_datasource_delimiter and !$this->getDataSourceSubmitOnSelection()) {
465 $tpl->setVariable('SEL_AUTOCOMPLETE', $sel_auto);
466 $tpl->setVariable('URL_AUTOCOMPLETE', $this->getDataSource());
467 } elseif ($this->getDataSourceSubmitOnSelection()) {
468 $tpl->setVariable('SEL_AUTOCOMPLETE_AUTOSUBMIT', $sel_auto);
469 $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_REQ', $this->getDataSource());
470 $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_RESP', $this->getDataSourceSubmitUrl());
471 } else {
472 $tpl->setVariable('AUTOCOMPLETE_DELIMITER', $this->ajax_datasource_delimiter);
473 $tpl->setVariable('SEL_AUTOCOMPLETE_DELIMITER', $sel_auto);
474 $tpl->setVariable('URL_AUTOCOMPLETE_DELIMITER', $this->getDataSource());
475 }
476 $tpl->parseCurrentBlock();
477
478 $tpl->setVariable('MORE_TXT', $lng->txt('autocomplete_more'));
479 }
480
481 if ($a_mode == "toolbar") {
482 // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
483 // -moz-inline-stack for FF2
484 // zoom 1; *display:inline for IE6 & 7
485 $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
486 } else {
487 $tpl->setVariable("STYLE_PAR", '');
488 }
489
490 if ($this->isHtmlAutoCompleteDisabled()) {
491 $tpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
492 }
493
494 if ($this->getRequired()) {
495 $tpl->setVariable("REQUIRED", "required=\"required\"");
496 }
497
498 // multi icons
499 if ($this->getMulti() && !$a_mode && !$this->getDisabled()) {
500 $tpl->touchBlock("inline_in_bl");
501 $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
502 }
503
504 $tpl->setVariable("ARIA_LABEL", ilUtil::prepareFormOutput($this->getTitle()));
505
506 return $tpl->get();
507 }
508
514 public function insert($a_tpl)
515 {
516 $html = $this->render();
517
518 $a_tpl->setCurrentBlock("prop_generic");
519 $a_tpl->setVariable("PROP_GENERIC", $html);
520 $a_tpl->parseCurrentBlock();
521 }
522
526 public function getTableFilterHTML()
527 {
528 $html = $this->render();
529 return $html;
530 }
531
535 public function getToolbarHTML()
536 {
537 $html = $this->render("toolbar");
538 return $html;
539 }
540
544 public function setDisableHtmlAutoComplete($autocomplete)
545 {
546 $this->autocomplete_disabled = $autocomplete;
547 }
548
553 {
555 }
556}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
getMultiIconsHTML()
Get HTML for multiple value icons.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
setAlert($a_alert)
Set Alert Text.
getMultiValues()
Get multi values.
getFieldId()
Get Post Variable.
stripSlashesAddSpaceFallback($a_str)
Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727.
This class represents a property that may include a sub form.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
setInputType($a_type)
set input type
insert($a_tpl)
Insert property html.
setMaxLength($a_maxlength)
Set Max Length.
setValueByArray($a_values)
Set value by array.
getMaxLength()
Get Max Length.
setDataSource($href, $a_delimiter=null)
set datasource link for js autocomplete
getTableFilterHTML()
Get HTML for table filter.
setValidationFailureMessage($a_msg)
Set message string for validation failure.
setMultiValues(array $a_values)
Set multi values.
getToolbarHTML()
Get HTML for toolbar.
setDataSourceSubmitOnSelection($a_stat)
getInputType()
get input type
getInlineStyle()
Get inline style.
setSuffix($a_value)
Set suffix.
checkInput()
Check input, strip slashes etc.
getValidationRegexp()
Get validation regexp.
setValue($a_value)
Set Value.
__construct($a_title="", $a_postvar="")
Constructor.
setInlineStyle($a_style)
Set inline style.
getDataSource()
get datasource link for js autocomplete
setSubmitFormOnEnter($a_val)
Set submit form on enter.
getSubmitFormOnEnter()
Get submit form on enter.
setValidationRegexp($a_value)
Set validation regexp.
setSize($a_size)
Set Size.
setDisableHtmlAutoComplete($autocomplete)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
static initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
global $DIC
Definition: goto.php:24
Interface for multi values support.
Interface for property form input GUI classes that can be used in table filters.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc