Can force the typeof check of GETPOST into $fields for type text.

This commit is contained in:
Laurent Destailleur 2020-09-29 20:48:40 +02:00
parent 82da38df65
commit 879d041398
4 changed files with 22 additions and 9 deletions

View File

@ -141,8 +141,13 @@ if ($action == 'update' && !empty($permissiontoadd))
if (in_array($key, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'fk_user_modif', 'import_key'))) continue;
// Set value to update
if (in_array($object->fields[$key]['type'], array('text', 'html'))) {
$value = GETPOST($key, 'restricthtml');
if (preg_match('/^(text|html)/', $object->fields[$key]['type'])) {
$tmparray = explode(':', $object->fields[$key]['type']);
if (!empty($tmparray[1])) {
$value = GETPOST($key, $tmparray[1]);
} else {
$value = GETPOST($key, 'restricthtml');
}
} elseif ($object->fields[$key]['type'] == 'date') {
$value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year'));
} elseif ($object->fields[$key]['type'] == 'datetime') {

View File

@ -5800,7 +5800,7 @@ abstract class CommonObject
} elseif (in_array($type, array('mail', 'phone', 'url')))
{
$out = '<input type="text" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').($autofocusoncreate ? ' autofocus' : '').'>';
} elseif ($type == 'text')
} elseif (preg_match('/^text/', $type))
{
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{
@ -5810,7 +5810,7 @@ abstract class CommonObject
} else {
$out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>';
}
} elseif ($type == 'html')
} elseif (preg_match('/^html/', $type))
{
if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
{
@ -6584,7 +6584,7 @@ abstract class CommonObject
return 'Error bad setup of extrafield';
}
} else $value = '';
} elseif ($type == 'text' || $type == 'html')
} elseif (preg_match('/^(text|html)/', $type))
{
$value = dol_htmlentitiesbr($value);
} elseif ($type == 'password')

View File

@ -45,15 +45,23 @@ foreach ($object->fields as $key => $val)
print '<tr><td';
print ' class="titlefieldcreate';
if ($val['notnull'] > 0) print ' fieldrequired';
if ($val['type'] == 'text' || $val['type'] == 'html') print ' tdtop';
if (preg_match('/^(text|html)/', $val['type'])) print ' tdtop';
print '">';
if (!empty($val['help'])) print $form->textwithpicto($langs->trans($val['label']), $langs->trans($val['help']));
else print $langs->trans($val['label']);
print '</td>';
print '<td>';
if (in_array($val['type'], array('int', 'integer'))) $value = GETPOSTISSET($key) ?GETPOST($key, 'int') : $object->$key;
elseif ($val['type'] == 'text' || $val['type'] == 'html') $value = GETPOSTISSET($key) ?GETPOST($key, 'restricthtml') : $object->$key;
else $value = GETPOSTISSET($key) ?GETPOST($key, 'alpha') : $object->$key;
elseif (preg_match('/^(text|html)/', $val['type'])) {
$tmparray = explode(':', $val['type']);
if (!empty($tmparray[1])) {
$check = $tmparray[1];
} else {
$check = 'restricthtml';
}
$value = GETPOSTISSET($key) ? GETPOST($key, $check) : $object->$key;
}
else $value = GETPOSTISSET($key) ? GETPOST($key, 'alpha') : $object->$key;
//var_dump($val.' '.$key.' '.$value);
if ($val['noteditable']) print $object->showOutputField($val, $key, $value, '', '', '', 0);
else print $object->showInputField($val, $key, $value, '', '', '', 0);

View File

@ -70,7 +70,7 @@ class MyObject extends CommonObject
/**
* 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
* 'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]', 'varchar(x)', 'double(24,8)', 'real', 'price', 'text', 'text:none', 'html', 'date', 'datetime', 'timestamp', 'duration', 'mail', 'phone', 'url', 'password')
* Note: Filter can be a string like "(t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL)"
* 'label' the translation key.
* 'enabled' is a condition when the field must be managed (Example: 1 or '$conf->global->MY_SETUP_PARAM)