dolibarr 24.0.0-beta
textfield.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2025 Open-Dsi <support@open-dsi.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
24require_once DOL_DOCUMENT_ROOT . '/core/class/fields/commonfield.class.php';
25require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
26
27
32{
36 public $emptyValues = array('');
37
38
51 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
52 {
53 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
54 $htmlName = $keyPrefix . $key . $keySuffix;
55
56 return self::$form->inputType('text', $htmlName, (string) $value, $htmlName, $moreCss, $moreAttrib);
57 }
58
71 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
72 {
73 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
74 $moreAttrib = trim((string) $moreAttrib);
75 if (empty($moreAttrib)) $moreAttrib = ' ' . $moreAttrib;
76 $htmlName = $keyPrefix . $key . $keySuffix;
77
78 return self::$form->inputText($htmlName, (string) $value, $moreCss, $moreAttrib, $fieldInfos->options);
79 }
80
93 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
94 {
95 if (!$this->isEmptyValue($fieldInfos, $value)) {
96 if (!empty($fieldInfos->options)) {
97 $value = str_replace(',', "\n", (string) $value);
98 }
99
100 return dol_htmlentitiesbr((string) $value);
101 }
102
103 return '';
104 }
105
115 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
116 {
117 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss);
118 }
119
129 public function verifyFieldValue($fieldInfos, $key, $value)
130 {
131 return parent::verifyFieldValue($fieldInfos, $key, $value);
132 }
133
144 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
145 {
146 $htmlName = $keyPrefix . $key . $keySuffix;
147 $value = GETPOST($htmlName, 'restricthtml');
148
149 return $this->verifyFieldValue($fieldInfos, $key, $value);
150 }
151
163 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
164 {
165 $htmlName = $keyPrefix . $key . $keySuffix;
166
167 if (GETPOSTISSET($htmlName)) {
168 if (!empty($fieldInfos->getPostCheck)) {
169 $value = GETPOST($htmlName, $fieldInfos->getPostCheck);
170 } else {
171 $value = GETPOST($htmlName, 'nohtml');
172 if (!empty($fieldInfos->options) && !empty($fieldInfos->multiInput)) {
173 $tmpArrayMultiSelect = GETPOST($htmlName . '_multiselect', 'array');
174 foreach ($tmpArrayMultiSelect as $tmpValue) {
175 $value .= (!empty($value) ? "," : "") . $tmpValue;
176 }
177 }
178 }
179 } else {
180 $value = $defaultValue;
181 }
182
183 return $value;
184 }
185
197 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
198 {
199 $htmlName = $keyPrefix . $key . $keySuffix;
200
201 if (GETPOSTISSET($htmlName)) {
202 $value = GETPOST($htmlName, 'alpha');
203 } else {
204 $value = $defaultValue;
205 }
206
207 return $value;
208 }
209
219 public function sqlFilterSearchField($fieldInfos, $key, $value)
220 {
221 if (!$this->isEmptyValue($fieldInfos, $value)) {
222 $alias = $fieldInfos->sqlAlias ?? 't.';
223
224 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 0);
225 }
226
227 return '';
228 }
229}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to text field.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...