From 4fc1fe798c3c3bb70c9fa251ea60cd034038f9df Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sun, 12 May 2013 18:20:28 +0200
Subject: [PATCH] Fix: Bad check on mandatory parameters

---
 htdocs/adherents/fiche.php | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php
index 05833bbce10..8c714ab7c67 100644
--- a/htdocs/adherents/fiche.php
+++ b/htdocs/adherents/fiche.php
@@ -246,9 +246,22 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
 	{
 		$birthdate=dol_mktime(12, 0, 0, $_POST["birthmonth"], $_POST["birthday"], $_POST["birthyear"]);
 	}
+	$lastname=$_POST["lastname"];
+	$firstname=$_POST["firstname"];
+	$morphy=$morphy=$_POST["morphy"];;
+	if ($morphy != 'mor' && empty($lastname)) {
+		$error++;
+		$langs->load("errors");
+		$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname"))."<br>\n";
+	}
+	if ($morphy != 'mor' && (!isset($firstname) || $firstname=='')) {
+		$error++;
+		$langs->load("errors");
+		$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentities("Firstname"))."<br>\n";
+	}
 
 	// Create new object
-	if ($result > 0)
+	if ($result > 0 && ! $error)
 	{
 		$object->oldcopy=dol_clone($object);
 
@@ -389,6 +402,10 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->adherent->creer)
 			$action='';
 		}
 	}
+	else
+	{
+		$action='edit';
+	}
 }
 
 if ($action == 'add' && $user->rights->adherent->creer)
@@ -489,7 +506,7 @@ if ($action == 'add' && $user->rights->adherent->creer)
 			$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentities("Password"))."<br>\n";
 		}
 	}
-	if (empty($lastname)) {
+	if ($morphy != 'mor' && empty($lastname)) {
 		$error++;
 		$langs->load("errors");
 		$errmsg .= $langs->trans("ErrorFieldRequired",$langs->transnoentities("Lastname"))."<br>\n";
-- 
GitLab