diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index 0f35a4a04e9..912c9953229 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -182,7 +182,7 @@ if ($action == 'update' && !empty($permissiontoadd)) // Fill array 'array_options' with data from add form if (!$error) { - $ret = $extrafields->setOptionalsFromPost(null, $object); + $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET'); if ($ret < 0) $error++; } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index dd3e9c2fc54..77a4c155fa6 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5848,7 +5848,7 @@ abstract class CommonObject * Update an extra field value for the current object. * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) * - * @param string $key Key of the extrafield (without starting 'options_') + * @param string $key Key of the extrafield to update (without starting 'options_') * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) * @param User $userused Object user * @return int -1=error, O=did nothing, 1=OK @@ -7159,8 +7159,6 @@ abstract class CommonObject $html_id = (empty($this->id) ? '' : 'extrarow-'.$this->element.'_'.$key.'_'.$this->id); - $out .= ''; - if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan = '0'; } if ($action == 'selectlines') { $colspan++; } @@ -7190,6 +7188,7 @@ abstract class CommonObject $labeltoshow = $langs->trans($label); $helptoshow = $langs->trans($extrafields->attributes[$this->table_element]['help'][$key]); + $out .= ''; $out .= ' When we make update of only one extrafield ($action = 'update_extras'), calling page can set this to avoid to have other extrafields being reset. + * '@GETPOSTISSET' => When we make update of extrafields ($action = 'update'), calling page can set this to avoid to have fields not into POST being reset. * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) */ public function setOptionalsFromPost($extralabels, &$object, $onlykey = '') @@ -2034,7 +2036,8 @@ class ExtraFields // Get extra fields foreach ($extralabels as $key => $value) { - if (!empty($onlykey) && $key != $onlykey) continue; + if (!empty($onlykey) && $onlykey != '@GETPOSTISSET' && $key != $onlykey) continue; + if (!empty($onlykey) && $onlykey == '@GETPOSTISSET' && ! GETPOSTISSET('options_'.$key)) continue; $key_type = $this->attributes[$object->table_element]['type'][$key]; if ($key_type == 'separate') continue;