diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php
index d8a1a85debf0ff0aa07b1e6602a4949a5c988990..94f12a61f8bf60d18391b08917d138fcac102617 100644
--- a/htdocs/adherents/card.php
+++ b/htdocs/adherents/card.php
@@ -302,6 +302,7 @@ if (empty($reshook))
 
 			// Fill array 'array_options' with data from add form
 			$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+			if ($ret < 0) $error++;
 
 			// Check if we need to also synchronize user information
 			$nosyncuser=0;
@@ -471,6 +472,7 @@ if (empty($reshook))
 
 		// Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+		if ($ret < 0) $error++;
 
 		// Check parameters
 		if (empty($morphy) || $morphy == "-1") {
diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php
index 96e1356182538911bf5ac7484ff22909e4ca83f3..ea39a200c97401dc4654c574b03e27e4b32f3a42 100644
--- a/htdocs/adherents/type.php
+++ b/htdocs/adherents/type.php
@@ -89,6 +89,7 @@ if ($action == 'add' && $user->rights->adherent->configurer)
 
 		// Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$adht);
+		if ($ret < 0) $error++;
 
 		if ($adht->libelle)
 		{
@@ -126,6 +127,7 @@ if ($action == 'update' && $user->rights->adherent->configurer)
 
 		// Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$adht);
+		if ($ret < 0) $error++;
 
 		$adht->update($user);
 
diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php
index 672c92b9508abf41a72e14390923ba85c3acfaf1..8a587d7de32b3bec9bffacd6f00aacd09dca1704 100644
--- a/htdocs/categories/card.php
+++ b/htdocs/categories/card.php
@@ -127,6 +127,7 @@ if ($action == 'add' && $user->rights->categorie->creer)
 	if ($parent != "-1") $object->fk_parent = $parent;
 
 	$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+	if ($ret < 0) $error++;
 
 	if (! $object->label)
 	{
diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php
index aa82fdb455d82aecb7981225c8c768c3d2bf0951..a105d1040361f8d58f502fafd3cb867c9c25be76 100644
--- a/htdocs/categories/edit.php
+++ b/htdocs/categories/edit.php
@@ -90,7 +90,8 @@ if ($action == 'update' && $user->rights->categorie->creer)
 	if (empty($categorie->error))
 	{
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$categorie);
-		
+		if ($ret < 0) $error++;
+
 		if ($categorie->update($user) > 0)
 		{
 			header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type);
diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index 0a4b255884aee210be65e243933b1e2ff1355666..c15b1fe4f32991bb3787d49972e3d8d5cb068ab9 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -274,6 +274,7 @@ if ($action == 'add')
 
 	// Fill array 'array_options' with data from add form
 	$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+	if ($ret < 0) $error++;
 
 	if (! $error)
 	{
@@ -429,6 +430,7 @@ if ($action == 'update')
 
 		// Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+		if ($ret < 0) $error++;
 
 		if (! $error)
 		{
diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php
index 030aff46434e41c9a2ae556fa8e96fba06f71fda..3739b59c33861f08c1e06b3515f609d2bf0015b7 100644
--- a/htdocs/comm/propal.php
+++ b/htdocs/comm/propal.php
@@ -1080,10 +1080,10 @@ if (empty($reshook))
 		// Fill array 'array_options' with data from update form
 		$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 		$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
-		if ($ret < 0)
-			$error ++;
+		if ($ret < 0) $error++;
 
-		if (! $error) {
+		if (! $error)
+		{
 			// Actions on extra fields (by external module or standard code)
 			// FIXME le hook fait double emploi avec le trigger !!
 			$hookmanager->initHooks(array('propaldao'));
diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php
index 5b76dd59323150d14060ec99d666ab71364cb08b..eb5767b173a241fbea78443da34d870132c15500 100644
--- a/htdocs/commande/card.php
+++ b/htdocs/commande/card.php
@@ -271,8 +271,7 @@ if (empty($reshook))
 
 				// Fill array 'array_options' with data from add form
 				$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
-				if ($ret < 0)
-					$error ++;
+				if ($ret < 0) $error++;
 
 				if (! $error)
 				{
@@ -365,10 +364,10 @@ if (empty($reshook))
 			} else {
 				// Fill array 'array_options' with data from add form
 				$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
-				if ($ret < 0)
-					$error ++;
+				if ($ret < 0) $error++;
 
-				if (! $error) {
+				if (! $error)
+				{
 					$object_id = $object->create($user);
 
 					// If some invoice's lines already known
@@ -1124,8 +1123,7 @@ if (empty($reshook))
 		// Fill array 'array_options' with data from update form
 		$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 		$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
-		if ($ret < 0)
-			$error ++;
+		if ($ret < 0) $error++;
 
 		if (! $error) {
 			// Actions on extra fields (by external module or standard code)
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 5f1f3998b5d24ecd2e9c1824453dfad37f3704c7..3d7a71f81335949f173e56e76e92150e0a0e1c0b 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -585,7 +585,7 @@ if (empty($reshook))
 			$discount->fk_facture_source = $object->id;
 
 			$error = 0;
-			
+
 			foreach ($amount_ht as $tva_tx => $xxx) {
 				$discount->amount_ht = abs($amount_ht [$tva_tx]);
 				$discount->amount_tva = abs($amount_tva [$tva_tx]);
@@ -636,7 +636,7 @@ if (empty($reshook))
 		// Fill array 'array_options' with data from add form
 		$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 		$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
-		if ($ret < 0) $error ++;
+		if ($ret < 0) $error++;
 
 		// Replacement invoice
 		if ($_POST['type'] == Facture::TYPE_REPLACEMENT)
@@ -1676,8 +1676,7 @@ if (empty($reshook))
 		// Fill array 'array_options' with data from add form
 		$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 		$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
-		if ($ret < 0)
-			$error ++;
+		if ($ret < 0) $error++;
 
 		if (! $error) {
 			// Actions on extra fields (by external module or standard code)
diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php
index af07cbb9a62fd5ae88ff8e84425695c979ecb6c2..248352dfee3046ae9cb7fedc8efac34baa289b03 100644
--- a/htdocs/contact/card.php
+++ b/htdocs/contact/card.php
@@ -200,6 +200,7 @@ if (empty($reshook))
 
         // Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+		if ($ret < 0) $error++;
 
         if (! GETPOST("lastname"))
         {
@@ -303,6 +304,7 @@ if (empty($reshook))
 
             // Fill array 'array_options' with data from add form
 			$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+			if ($ret < 0) $error++;
 
             $result = $object->update($contactid, $user);
 
diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php
index fdd0acfec74fa922dc618bba7ea270284b668ec9..6d10442caf7e2fe47387ec519980ecd560be7d08 100644
--- a/htdocs/contrat/card.php
+++ b/htdocs/contrat/card.php
@@ -355,6 +355,7 @@ if ($action == 'add' && $user->rights->contrat->creer)
 
 	    	// Fill array 'array_options' with data from add form
 	    	$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
+			if ($ret < 0) $error++;
 
 	        $result = $object->create($user);
 	        if ($result > 0)
@@ -702,19 +703,20 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra
 	// Fill array 'array_options' with data from update form
 	$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 	$ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute'));
-	if ($ret < 0)
-		$error ++;
-
-	if (! $error) {
+	if ($ret < 0) $error++;
 
-			$result = $object->insertExtraFields();
-			if ($result < 0) {
-				$error ++;
-			}
-		} else if ($reshook < 0)
-			$error ++;
+	if (! $error)
+	{
+		$result = $object->insertExtraFields();
+		if ($result < 0)
+		{
+			$error++;
+		}
+	}
+	else if ($reshook < 0) $error++;
 
-	if ($error) {
+	if ($error)
+	{
 		$action = 'edit_extras';
 		setEventMessage($object->error,'errors');
 	}
diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php
index 008dff0f019b30a9e3ecab3dccabf7e2880268d1..cc602d08ed584864a9775f8b59c87cd1b7ad8df3 100644
--- a/htdocs/core/class/extrafields.class.php
+++ b/htdocs/core/class/extrafields.class.php
@@ -1063,7 +1063,7 @@ class ExtraFields
 	 * @param   array	$extralabels    $array of extrafields
 	 * @param   object	$object         Object
 	 * @param	string	$onlykey		Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset.
-	 * @return	int						1 if array_options set / 0 if no value
+	 * @return	int						1 if array_options set, 0 if no value, -1 if error (field required missing for example)
 	 */
 	function setOptionalsFromPost($extralabels,&$object,$onlykey='')
 	{
diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php
index 28b492651c090f6a08cdc8c9c51aca2fd370d913..0257b51c946936388c4976f160342a41cf92ff7f 100644
--- a/htdocs/fourn/commande/card.php
+++ b/htdocs/fourn/commande/card.php
@@ -783,7 +783,7 @@ if ($action == 'update_extras')
 	$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
 	if ($ret < 0) $error++;
 
-	if (!$error)
+	if (! $error)
 	{
 		// Actions on extra fields (by external module or standard code)
 		// FIXME le hook fait double emploi avec le trigger !!
@@ -842,19 +842,26 @@ if ($action == 'add' && $user->rights->fournisseur->commande->creer)
 		$object->date_livraison = $datelivraison;
 
 		// Fill array 'array_options' with data from add form
-        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
-
-        $id = $object->create($user);
-		if ($id < 0)
-		{
-			$error++;
-		}
+       	if (! $error)
+       	{
+			$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+			if ($ret < 0) $error++;
+       	}
+
+       	if (! $error)
+       	{
+			$id = $object->create($user);
+        	if ($id < 0)
+        	{
+        		$error++;
+	        	setEventMessage($langs->trans($object->error), 'errors');
+        	}
+        }
 
         if ($error)
         {
             $langs->load("errors");
             $db->rollback();
-	        setEventMessage($langs->trans($object->error), 'errors');
             $action='create';
             $_GET['socid']=$_POST['socid'];
         }
diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php
index a10aa89ae657b4f111f06f7a91ca3de51397bd79..54ef660f6aa7981b0b277fa4e8fe96c80ba01ae0 100644
--- a/htdocs/fourn/facture/card.php
+++ b/htdocs/fourn/facture/card.php
@@ -308,7 +308,7 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
 
         $extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
 		$ret = $extrafields->setOptionalsFromPost($extralabels, $object);
-		if ($ret < 0) $error ++;
+		if ($ret < 0) $error++;
 
         $tmpproject = GETPOST('projectid', 'int');
 
@@ -1071,8 +1071,7 @@ elseif ($action == 'update_extras')
 	// Fill array 'array_options' with data from add form
 	$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
 	$ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute'));
-
-	if($ret < 0) $error++;
+	if ($ret < 0) $error++;
 
 	if (!$error)
 	{
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index a4c4e4ee92edd923169049e607f986ad201b7ee8..b5f34e20a8d08b2572a640fdf58e51dc75bcd34e 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -262,8 +262,12 @@ if (empty($reshook))
 
             // Fill array 'array_options' with data from add form
         	$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+			if ($ret < 0) $error++;
 
-            $id = $object->create($user);
+			if (! $error)
+			{
+            	$id = $object->create($user);
+			}
 
             if ($id > 0)
             {
@@ -339,8 +343,9 @@ if (empty($reshook))
 
                 // Fill array 'array_options' with data from add form
         		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+				if ($ret < 0) $error++;
 
-                if ($object->check())
+                if (! $error && $object->check())
                 {
                     if ($object->update($object->id, $user) > 0)
                     {
diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php
index b376133699b6339986775de56072bb8aab951023..1c971ef9e3585e15a9036063dc33522b8b6271ad 100644
--- a/htdocs/projet/card.php
+++ b/htdocs/projet/card.php
@@ -147,6 +147,7 @@ if (empty($reshook))
 
 	        // Fill array 'array_options' with data from add form
 	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+			if ($ret < 0) $error++;
 
 	        $result = $object->create($user);
 	        if ($result > 0)
@@ -222,10 +223,7 @@ if (empty($reshook))
 
 	        // Fill array 'array_options' with data from add form
 	        $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
-			if ($ret < 0)
-			{
-				$error++;
-			}
+			if ($ret < 0) $error++;
 	    }
 
 	    if (! $error)
diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php
index 11bc8ffea096bc293bcb9c96c758b0d3ab7fd20b..a9cd64e33b53e154e251d28a4ee95ed7c397b29f 100644
--- a/htdocs/projet/tasks/task.php
+++ b/htdocs/projet/tasks/task.php
@@ -91,12 +91,15 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer)
 
 		// Fill array 'array_options' with data from add form
 		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+		if ($ret < 0) $error++;
 
-		$result=$object->update($user);
-
-		if ($result < 0)
+		if (! $error)
 		{
-		    setEventMessages($object->error,$object->errors,'errors');
+			$result=$object->update($user);
+			if ($result < 0)
+			{
+			    setEventMessages($object->error,$object->errors,'errors');
+			}
 		}
 	}
 	else
diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php
index c8628bd26a0e63205ecd08db7d630e64fcd8a2a3..255e7fe9134f8ebd72f00af5649a13fc0f5efc41 100644
--- a/htdocs/public/members/new.php
+++ b/htdocs/public/members/new.php
@@ -250,6 +250,7 @@ if ($action == 'add')
         // Fill array 'array_options' with data from add form
         $extralabels=$extrafields->fetch_name_optionals_label($adh->table_element);
         $ret = $extrafields->setOptionalsFromPost($extralabels,$adh);
+		if ($ret < 0) $error++;
 
         $result=$adh->create($user);
         if ($result > 0)
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 72e249ce5424b90dd6d845023fbf24f379917d9f..065bbbc0ac80e8f7e02cc8911968843994f8e743 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -195,7 +195,7 @@ if (empty($reshook))
 
         // Fill array 'array_options' with data from add form
         $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
-
+		if ($ret < 0) $error++;
 
         if (GETPOST('deletephoto')) $object->logo = '';
         else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
diff --git a/htdocs/user/card.php b/htdocs/user/card.php
index ec6b65e534cf43461dbab3a697a3d50618d2a99d..7c5caf5254a42dd74b3974df46bd4c0e4130484f 100644
--- a/htdocs/user/card.php
+++ b/htdocs/user/card.php
@@ -211,6 +211,7 @@ if ($action == 'add' && $canadduser)
 
         // Fill array 'array_options' with data from add form
         $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+		if ($ret < 0) $error++;
 
         // If multicompany is off, admin users must all be on entity 0.
         $entity=GETPOST('entity','int');
@@ -358,6 +359,7 @@ if ($action == 'update' && ! $_POST["cancel"])
 
             // Fill array 'array_options' with data from add form
         	$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+			if ($ret < 0) $error++;
 
             if (! empty($conf->multicompany->enabled))
             {
@@ -382,20 +384,22 @@ if ($action == 'update' && ! $_POST["cancel"])
             if (GETPOST('deletephoto')) $object->photo='';
             if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
 
-            $ret=$object->update($user);
-
-            if ($ret < 0)
+            if (! $error)
             {
-            	$error++;
-                if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
-                {
-                    $langs->load("errors");
-	                setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors');
-                }
-                else
-              {
-	              setEventMessage($object->error, 'errors');
-                }
+	            $ret=$object->update($user);
+	            if ($ret < 0)
+	            {
+	            	$error++;
+	                if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
+	                {
+	                    $langs->load("errors");
+		                setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors');
+	                }
+	                else
+	              {
+		              setEventMessage($object->error, 'errors');
+	                }
+	            }
             }
 
             if (! $error && isset($_POST['contactid']))
diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php
index a1930f7c027eac8362a01d32892df51d03e1b3ea..56cfc5d9ee82261c6488455a5a1ccb373d2f0310 100644
--- a/htdocs/user/group/card.php
+++ b/htdocs/user/group/card.php
@@ -101,6 +101,7 @@ if ($action == 'add')
 
 			// Fill array 'array_options' with data from add form
       		$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+			if ($ret < 0) $error++;
 
       		if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0;
 			else $object->entity = $_POST["entity"];
@@ -183,6 +184,7 @@ if ($action == 'update')
 
 		// Fill array 'array_options' with data from add form
       	$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
+		if ($ret < 0) $error++;
 
 		if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0;
 		else $object->entity = $_POST["entity"];