24require_once DOL_DOCUMENT_ROOT .
'/core/class/html.form.class.php';
25require_once DOL_DOCUMENT_ROOT .
'/core/class/validate.class.php';
46 public $errors = array();
66 public static $validator;
71 public $emptyValues = array(
'', 0, array());
85 $this->errors = array();
88 $this->
type = strtolower(substr(get_class($this), 0, -5));
89 $this->label =
'FieldLabel' . ucfirst($this->
type);
91 if (!isset(self::$form)) {
92 if (!is_object($form)) {
93 $form =
new Form($this->db);
98 if (!isset(self::$validator)) {
100 $validator =
new Validate($this->db, $langs);
113 self::$form = &$form;
124 self::$validator = &$validator;
135 $this->errors = array();
146 return $this->error . (is_array($this->errors) ? (!empty($this->error) ? $separator :
'') . implode($separator, $this->errors) :
'');
159 if (!isset($value)) {
163 if (!is_array($emptyValues)) {
164 $emptyValues = !empty($fieldInfos->emptyValues) && is_array($fieldInfos->emptyValues) ? $fieldInfos->emptyValues : $this->emptyValues;
167 foreach ($emptyValues as $val) {
168 if ($val === $value) {
188 public function printInputSearchField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
205 public function printInputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
222 public function printOutputField($fieldInfos, $key, $value, $keyPrefix =
'', $keySuffix =
'', $moreCss =
'', $moreAttrib =
'')
236 public function getInputCss($fieldInfos, $moreCss =
'', $defaultCss =
'minwidth400')
238 if (empty($moreCss)) {
239 if (!empty($fieldInfos->css)) {
240 $moreCss = $fieldInfos->css;
241 } elseif (!empty($defaultCss)) {
242 $moreCss = $defaultCss;
245 $moreCss = trim((
string) $moreCss);
247 return empty($moreCss) ?
'' :
' ' . $moreCss;
263 $required = $fieldInfos->required;
264 $minLength = $fieldInfos->minLength ?? 0;
265 $maxLength = $fieldInfos->maxLength ?? 0;
269 self::$validator->error =
'';
275 self::$validator->error = $langs->trans(
'RequireANotEmptyValue');
284 if (!empty($minLength) && is_string($value) && !self::$validator->isMinLength($value, $minLength)) {
289 if (!empty($maxLength) && is_string($value) && !self::$validator->isMaxLength($value, $maxLength)) {
295 if (isset($fieldInfos->minValue) && is_numeric($value) && ((
float) $value) < $fieldInfos->minValue) {
296 self::$validator->error = $langs->trans(
'RequireMinValue', $fieldInfos->minValue);
301 if (isset($fieldInfos->maxValue) && is_numeric($value) && ((
float) $value) > $fieldInfos->maxValue) {
302 self::$validator->error = $langs->trans(
'RequireMaxValue', $fieldInfos->maxValue);
321 $htmlName = $keyPrefix . $key . $keySuffix;
337 public function getPostFieldValue($fieldInfos, $key, $defaultValue =
null, $keyPrefix =
'', $keySuffix =
'')
339 return $defaultValue;
355 return $defaultValue;
getInputCss($fieldInfos, $moreCss='', $defaultCss='minwidth400')
Get input CSS.
sqlFilterSearchField($fieldInfos, $key, $value)
Get sql filter for search field.
errorsToString($separator=', ')
Method to output saved errors.
verifyPostFieldValue($fieldInfos, $key, $keyPrefix='', $keySuffix='')
Verify if the field value from GET/POST is valid.
printInputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input field into a page.
getPostFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get field value from GET/POST.
getPostSearchFieldValue($fieldInfos, $key, $defaultValue=null, $keyPrefix='', $keySuffix='')
Get search field value from GET/POST.
clearErrors()
clear errors
static setForm(&$form)
Set form used for print the field.
verifyFieldValue($fieldInfos, $key, $value)
Verify if the field value is valid.
static setValidator(&$validator)
Set validator used for check the field value.
printInputSearchField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to put an input search field into a page.
printOutputField($fieldInfos, $key, $value, $keyPrefix='', $keySuffix='', $moreCss='', $moreAttrib='')
Return HTML string to show a field into a page.
__construct($db)
Constructor.
isEmptyValue($fieldInfos, $value, $emptyValues=null)
Check if the value is deemed as empty.
Class toolbox to validate values.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...