dolibarr 24.0.0-beta
htmlfield.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';
25
26
27// TODO same as text field ?
28
33{
37 public $emptyValues = array('');
38
39
52 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
53 {
54 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
55 $htmlName = $keyPrefix . $key . $keySuffix;
56
57 return self::$form->inputType('text', $htmlName, $value, $htmlName, $moreCss, $moreAttrib);
58 }
59
72 public function printInputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
73 {
74 $moreCss = $this->getInputCss($fieldInfos, $moreCss);
75 $moreAttrib = trim((string) $moreAttrib);
76 if (empty($moreAttrib)) $moreAttrib = ' ' . $moreAttrib;
77 $htmlName = $keyPrefix . $key . $keySuffix;
78
79 return self::$form->inputHtml($htmlName, $value, $moreCss, $moreAttrib);
80 }
81
94 public function printOutputField($fieldInfos, $key, $value, $keyPrefix = '', $keySuffix = '', $moreCss = '', $moreAttrib = '')
95 {
96 if (!$this->isEmptyValue($fieldInfos, $value)) {
97 if (!empty($fieldInfos->options)) {
98 $value = str_replace(',', "\n", (string) $value);
99 }
100
101 return dol_htmlentitiesbr((string) $value);
102 }
103
104 return '';
105 }
106
116 public function getInputCss($fieldInfos, $moreCss = '', $defaultCss = '')
117 {
118 return parent::getInputCss($fieldInfos, $moreCss, $defaultCss);
119 }
120
130 public function verifyFieldValue($fieldInfos, $key, $value)
131 {
132 return parent::verifyFieldValue($fieldInfos, $key, $value);
133 }
134
145 public function verifyPostFieldValue($fieldInfos, $key, $keyPrefix = '', $keySuffix = '')
146 {
147 return parent::verifyPostFieldValue($fieldInfos, $key, $keyPrefix, $keySuffix);
148 }
149
161 public function getPostFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
162 {
163 $htmlName = $keyPrefix . $key . $keySuffix;
164
165 if (GETPOSTISSET($htmlName)) {
166 $value = GETPOST($htmlName, empty($fieldInfos->getPostCheck) ? 'restricthtml' : $fieldInfos->getPostCheck);
167 } else {
168 $value = $defaultValue;
169 }
170
171 return $value;
172 }
173
185 public function getPostSearchFieldValue($fieldInfos, $key, $defaultValue = null, $keyPrefix = '', $keySuffix = '')
186 {
187 $htmlName = $keyPrefix . $key . $keySuffix;
188
189 if (GETPOSTISSET($htmlName)) {
190 $value = GETPOST($htmlName, 'alpha');
191 } else {
192 $value = $defaultValue;
193 }
194
195 return $value;
196 }
197
207 public function sqlFilterSearchField($fieldInfos, $key, $value)
208 {
209 if (!$this->isEmptyValue($fieldInfos, $value)) {
210 $alias = $fieldInfos->sqlAlias ?? 't.';
211
212 return natural_search($alias . ($fieldInfos->nameInTable ?? $key), $value, 0);
213 }
214
215 return '';
216 }
217}
Class to common field.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class to html field.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
getInputCss($fieldInfos, $moreCss='', $defaultCss='')
Get input CSS.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
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...