ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 if ($this->getDisabled()) {
426 if ($this->getMulti()) {
427 $value = $this->getMultiValues();
428 $hidden = "";
429 if (is_array($value)) {
430 foreach ($value as $item) {
431 $hidden .= $this->getHiddenTag($postvar, $item);
432 }
433 }
434 } else {
435 $hidden = $this->getHiddenTag($postvar, $this->getValue());
436 }
437 if ($hidden) {
438 $tpl->setVariable("HIDDEN_INPUT", $hidden);
439 }
440 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
441 } else {
442 $tpl->setVariable("POST_VAR", $postvar);
443 }
444
445 // use autocomplete feature?
446 if ($this->getDataSource()) {
447 include_once "Services/jQuery/classes/class.iljQueryUtil.php";
450
451 if ($this->getMulti()) {
452 $tpl->setCurrentBlock("ac_multi");
453 $tpl->setVariable('MURL_AUTOCOMPLETE', $this->getDataSource());
454 $tpl->setVariable('ID_AUTOCOMPLETE', $this->getFieldId());
455 $tpl->parseCurrentBlock();
456
457 // set to fields that start with autocomplete selector
458 $sel_auto = '[id^="' . $this->getFieldId() . '"]';
459 } else {
460 // use id for autocomplete selector
461 $sel_auto = "#" . $this->getFieldId();
462 }
463
464 $tpl->setCurrentBlock("autocomplete_bl");
465 if (!$this->ajax_datasource_delimiter and !$this->getDataSourceSubmitOnSelection()) {
466 $tpl->setVariable('SEL_AUTOCOMPLETE', $sel_auto);
467 $tpl->setVariable('URL_AUTOCOMPLETE', $this->getDataSource());
468 } elseif ($this->getDataSourceSubmitOnSelection()) {
469 $tpl->setVariable('SEL_AUTOCOMPLETE_AUTOSUBMIT', $sel_auto);
470 $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_REQ', $this->getDataSource());
471 $tpl->setVariable('URL_AUTOCOMPLETE_AUTOSUBMIT_RESP', $this->getDataSourceSubmitUrl());
472 } else {
473 $tpl->setVariable('AUTOCOMPLETE_DELIMITER', $this->ajax_datasource_delimiter);
474 $tpl->setVariable('SEL_AUTOCOMPLETE_DELIMITER', $sel_auto);
475 $tpl->setVariable('URL_AUTOCOMPLETE_DELIMITER', $this->getDataSource());
476 }
477 $tpl->parseCurrentBlock();
478
479 $tpl->setVariable('MORE_TXT', $lng->txt('autocomplete_more'));
480 }
481
482 if ($a_mode == "toolbar") {
483 // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
484 // -moz-inline-stack for FF2
485 // zoom 1; *display:inline for IE6 & 7
486 $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
487 } else {
488 $tpl->setVariable("STYLE_PAR", '');
489 }
490
491 if ($this->isHtmlAutoCompleteDisabled()) {
492 $tpl->setVariable("AUTOCOMPLETE", "autocomplete=\"off\"");
493 }
494
495 if ($this->getRequired()) {
496 $tpl->setVariable("REQUIRED", "required=\"required\"");
497 }
498
499 // multi icons
500 if ($this->getMulti() && !$a_mode && !$this->getDisabled()) {
501 $tpl->touchBlock("inline_in_bl");
502 $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
503 }
504
505 $tpl->setVariable("ARIA_LABEL", ilUtil::prepareFormOutput($this->getTitle()));
506
507 return $tpl->get();
508 }
509
515 public function insert($a_tpl)
516 {
517 $html = $this->render();
518
519 $a_tpl->setCurrentBlock("prop_generic");
520 $a_tpl->setVariable("PROP_GENERIC", $html);
521 $a_tpl->parseCurrentBlock();
522 }
523
527 public function getTableFilterHTML()
528 {
529 $html = $this->render();
530 return $html;
531 }
532
536 public function getToolbarHTML()
537 {
538 $html = $this->render("toolbar");
539 return $html;
540 }
541
545 public function setDisableHtmlAutoComplete($autocomplete)
546 {
547 $this->autocomplete_disabled = $autocomplete;
548 }
549
554 {
556 }
557}
$tpl
Definition: ilias.php:10
$_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 initjQueryUI($a_tpl=null)
inits and adds the jQuery-UI JS-File to the global template (see included_components....
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$html
Definition: example_001.php:87
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.
font size
Definition: langcheck.php:162
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92