diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index b96edc31b2ce6f29e55b599a2f0b82b4c7afd3c0..de0a591cf98233ac56a6c2e365e0b16d5d50c92d 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -1737,40 +1737,41 @@ if (empty($reshook))
 				$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
 			}
 
-		if ($result >= 0) {
-			header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
-			exit();
-		} else {
-			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
-				$langs->load("errors");
-				setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
+			if ($result >= 0) {
+				header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
+				exit();
 			} else {
-				setEventMessage($object->error, 'errors');
+				if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
+					$langs->load("errors");
+					setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
+				} else {
+					setEventMessage($object->error, 'errors');
+				}
 			}
 		}
-	}
-
-	// bascule du statut d'un contact
-	else if ($action == 'swapstatut')
-	{
-		if ($object->fetch($id)) {
-			$result = $object->swapContactStatus(GETPOST('ligne'));
-		} else {
-			dol_print_error($db);
+	
+		// bascule du statut d'un contact
+		else if ($action == 'swapstatut')
+		{
+			if ($object->fetch($id)) {
+				$result = $object->swapContactStatus(GETPOST('ligne'));
+			} else {
+				dol_print_error($db);
+				}
+		}
+	
+		// Efface un contact
+		else if ($action == 'deletecontact')
+		{
+			$object->fetch($id);
+			$result = $object->delete_contact($lineid);
+	
+			if ($result >= 0) {
+				header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
+				exit();
+			} else {
+				dol_print_error($db);
 			}
-	}
-
-	// Efface un contact
-	else if ($action == 'deletecontact')
-	{
-		$object->fetch($id);
-		$result = $object->delete_contact($lineid);
-
-		if ($result >= 0) {
-			header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $object->id);
-			exit();
-		} else {
-			dol_print_error($db);
 		}
 	}
 
@@ -1790,17 +1791,16 @@ if (empty($reshook))
 			$reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by
 			                                                                                      // some hooks
 			if (empty($reshook)) {
-						$result = $object->insertExtraFields();
-					if ($result < 0) {
-						$error ++;
-					}
-				} else if ($reshook < 0)
+					$result = $object->insertExtraFields();
+				if ($result < 0) {
 					$error ++;
-			}
-
-			if ($error)
-				$action = 'edit_extras';
+				}
+			} else if ($reshook < 0)
+				$error ++;
 		}
+
+		if ($error)
+			$action = 'edit_extras';
 	}
 }