diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 787cad2664f..e76d41a6fd2 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -64,6 +64,9 @@ if (! empty($conf->mailmanspip->enabled))
$object = new Adherent($db);
$extrafields = new ExtraFields($db);
+// fetch optionals attributes and labels
+$extralabels=$extrafields->fetch_name_optionals_label('member');
+
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
$object->getCanvas($socid);
$canvas = $object->canvas?$object->canvas:GETPOST("canvas");
@@ -282,14 +285,8 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
$object->statut = $_POST["statut"];
$object->public = $_POST["public"];
- // Get extra fields
- foreach($_POST as $key => $value)
- {
- if (preg_match("/^options_/",$key))
- {
- $object->array_options[$key]=$_POST[$key];
- }
- }
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
// Check if we need to also synchronize user information
$nosyncuser=0;
@@ -451,14 +448,8 @@ if ($action == 'add' && $user->rights->adherent->creer)
$object->fk_soc = $socid;
$object->public = $public;
- // Get extra fields
- foreach($_POST as $key => $value)
- {
- if (preg_match("/^options_/",$key))
- {
- $object->array_options[$key]=$_POST[$key];
- }
- }
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
// Check parameters
if (empty($morphy) || $morphy == "-1") {
@@ -684,9 +675,6 @@ if ($user->rights->adherent->creer && $action == 'confirm_add_spip' && $confirm
$form = new Form($db);
$formcompany = new FormCompany($db);
-// fetch optionals attributes and labels
-$extralabels=$extrafields->fetch_name_optionals_label('member');
-
$help_url='EN:Module_Foundations|FR:Module_Adhérents|ES:Módulo_Miembros';
llxHeader('',$langs->trans("Member"),$help_url);
@@ -885,15 +873,7 @@ else
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
- foreach($extrafields->attribute_label as $key=>$label)
- {
- $value=(isset($_POST["options_".$key])?GETPOST('options_'.$key,'alpha'):(isset($object->array_options["options_".$key])?$object->array_options["options_".$key]:''));
- print '
'."\n";
- }
+ print $object->showOptionals($extrafields,'edit');
}
// Third party Dolibarr
@@ -1458,13 +1430,7 @@ else
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
- foreach($extrafields->attribute_label as $key=>$label)
- {
- $value=$object->array_options["options_$key"];
- print "
';
@@ -356,23 +334,13 @@ if ($rowid > 0)
// Other attributes
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$act,$action); // Note that $action and $object may have been modified by hook
-
- print '';
-
- //Extra field
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
- print '
';
}
- // Get extra fields
- foreach($_POST as $key => $value)
- {
- if (preg_match("/^options_/",$key))
- {
- $actioncomm->array_options[$key]=GETPOST($key);
- }
- }
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$actioncomm);
if (! $error)
{
@@ -343,14 +340,8 @@ if ($action == 'update')
}
$actioncomm->userdone = $userdone;
- // Get extra fields
- foreach($_POST as $key => $value)
- {
- if (preg_match("/^options_/",$key))
- {
- $actioncomm->array_options[$key]=GETPOST($key);
- }
- }
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$actioncomm);
if (! $error)
{
@@ -395,9 +386,6 @@ llxHeader('',$langs->trans("Agenda"),$help_url);
$form = new Form($db);
$htmlactions = new FormActions($db);
-// fetch optionals attributes and labels
-$extralabels=$extrafields->fetch_name_optionals_label('actioncomm');
-
if ($action == 'create')
{
$contact = new Contact($db);
@@ -603,22 +591,13 @@ if ($action == 'create')
$parameters=array();
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$actioncomm,$action); // Note that $action and $object may have been modified by hook
- print '';
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
- print '
'."\n";
- }
+ print $object->showOptionals($extrafields,'edit');
}
// Template to use by default
@@ -2091,15 +2083,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
- foreach($extrafields->attribute_label as $key=>$label)
- {
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
- print '
';
diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php
index 1ef52efc85b..be62afba37f 100644
--- a/htdocs/user/fiche.php
+++ b/htdocs/user/fiche.php
@@ -187,14 +187,8 @@ if ($action == 'add' && $canadduser)
$object->note = GETPOST("note");
$object->ldap_sid = GETPOST("ldap_sid");
- // Get extra fields
- foreach($_POST as $key => $value)
- {
- if (preg_match("/^options_/",$key))
- {
- $object->array_options[$key]=GETPOST($key);
- }
- }
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
// If multicompany is off, admin users must all be on entity 0.
if (! empty($conf->multicompany->enabled))
@@ -329,14 +323,8 @@ if ($action == 'update' && ! $_POST["cancel"])
$object->openid = GETPOST("openid");
$object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0;
- // Get extra fields
- foreach($_POST as $key => $value)
- {
- if (preg_match("/^options_/",$key))
- {
- $object->array_options[$key]=GETPOST($key);
- }
- }
+ // Fill array 'array_options' with data from add form
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if (! empty($conf->multicompany->enabled))
{
@@ -927,15 +915,7 @@ if (($action == 'create') || ($action == 'adduserldap'))
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook) && ! empty($extrafields->attribute_label))
{
- foreach($extrafields->attribute_label as $key=>$label)
- {
- $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
- print '