Fix stay on create form if creation fails

This commit is contained in:
Laurent Destailleur 2017-09-30 18:19:20 +02:00
parent fa6c3eff80
commit 9ba8b9bf7e

View File

@ -310,159 +310,155 @@ if (empty($reshook))
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdPartyName")), null, 'errors');
$error++; $error++;
$action=($action=='add'?'create':'edit');
} }
if (GETPOST('client') < 0) if (GETPOST('client') < 0)
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProspectCustomer")), null, 'errors');
$error++; $error++;
$action=($action=='add'?'create':'edit');
} }
if (GETPOST('fournisseur') < 0) if (GETPOST('fournisseur') < 0)
{ {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Supplier")), null, 'errors');
$error++; $error++;
$action=($action=='add'?'create':'edit');
} }
if ($action == 'update') if ($error)
{ {
$ret=$object->fetch($socid); if ($action == 'update')
$object->oldcopy = clone $object; {
} $ret=$object->fetch($socid);
else $object->canvas=$canvas; $object->oldcopy = clone $object;
}
else $object->canvas=$canvas;
if (GETPOST("private") == 1) // Ask to create a contact if (GETPOST("private") == 1) // Ask to create a contact
{ {
$object->particulier = GETPOST("private"); $object->particulier = GETPOST("private");
$object->name = dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha')); $object->name = dolGetFirstLastname(GETPOST('firstname','alpha'),GETPOST('name','alpha'));
$object->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int $object->civility_id = GETPOST('civility_id'); // Note: civility id is a code, not an int
// Add non official properties // Add non official properties
$object->name_bis = GETPOST('name','alpha'); $object->name_bis = GETPOST('name','alpha');
$object->firstname = GETPOST('firstname','alpha'); $object->firstname = GETPOST('firstname','alpha');
} }
else else
{ {
$object->name = GETPOST('name', 'alpha'); $object->name = GETPOST('name', 'alpha');
} }
$object->name_alias = GETPOST('name_alias'); $object->name_alias = GETPOST('name_alias');
$object->address = GETPOST('address'); $object->address = GETPOST('address');
$object->zip = GETPOST('zipcode', 'alpha'); $object->zip = GETPOST('zipcode', 'alpha');
$object->town = GETPOST('town', 'alpha'); $object->town = GETPOST('town', 'alpha');
$object->country_id = GETPOST('country_id', 'int'); $object->country_id = GETPOST('country_id', 'int');
$object->state_id = GETPOST('state_id', 'int'); $object->state_id = GETPOST('state_id', 'int');
$object->skype = GETPOST('skype', 'alpha'); $object->skype = GETPOST('skype', 'alpha');
$object->phone = GETPOST('phone', 'alpha'); $object->phone = GETPOST('phone', 'alpha');
$object->fax = GETPOST('fax','alpha'); $object->fax = GETPOST('fax','alpha');
$object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL)); $object->email = trim(GETPOST('email', 'custom', 0, FILTER_SANITIZE_EMAIL));
$object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL)); $object->url = trim(GETPOST('url', 'custom', 0, FILTER_SANITIZE_URL));
$object->idprof1 = trim(GETPOST('idprof1', 'alpha')); $object->idprof1 = trim(GETPOST('idprof1', 'alpha'));
$object->idprof2 = trim(GETPOST('idprof2', 'alpha')); $object->idprof2 = trim(GETPOST('idprof2', 'alpha'));
$object->idprof3 = trim(GETPOST('idprof3', 'alpha')); $object->idprof3 = trim(GETPOST('idprof3', 'alpha'));
$object->idprof4 = trim(GETPOST('idprof4', 'alpha')); $object->idprof4 = trim(GETPOST('idprof4', 'alpha'));
$object->idprof5 = trim(GETPOST('idprof5', 'alpha')); $object->idprof5 = trim(GETPOST('idprof5', 'alpha'));
$object->idprof6 = trim(GETPOST('idprof6', 'alpha')); $object->idprof6 = trim(GETPOST('idprof6', 'alpha'));
$object->prefix_comm = GETPOST('prefix_comm', 'alpha'); $object->prefix_comm = GETPOST('prefix_comm', 'alpha');
$object->code_client = GETPOST('code_client', 'alpha'); $object->code_client = GETPOST('code_client', 'alpha');
$object->code_fournisseur = GETPOST('code_fournisseur', 'alpha'); $object->code_fournisseur = GETPOST('code_fournisseur', 'alpha');
$object->capital = GETPOST('capital', 'alpha'); $object->capital = GETPOST('capital', 'alpha');
$object->barcode = GETPOST('barcode', 'alpha'); $object->barcode = GETPOST('barcode', 'alpha');
$object->tva_intra = GETPOST('tva_intra', 'alpha'); $object->tva_intra = GETPOST('tva_intra', 'alpha');
$object->tva_assuj = GETPOST('assujtva_value', 'alpha'); $object->tva_assuj = GETPOST('assujtva_value', 'alpha');
$object->status = GETPOST('status', 'alpha'); $object->status = GETPOST('status', 'alpha');
// Local Taxes // Local Taxes
$object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha'); $object->localtax1_assuj = GETPOST('localtax1assuj_value', 'alpha');
$object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha'); $object->localtax2_assuj = GETPOST('localtax2assuj_value', 'alpha');
$object->localtax1_value = GETPOST('lt1', 'alpha'); $object->localtax1_value = GETPOST('lt1', 'alpha');
$object->localtax2_value = GETPOST('lt2', 'alpha'); $object->localtax2_value = GETPOST('lt2', 'alpha');
$object->forme_juridique_code = GETPOST('forme_juridique_code', 'int'); $object->forme_juridique_code = GETPOST('forme_juridique_code', 'int');
$object->effectif_id = GETPOST('effectif_id', 'int'); $object->effectif_id = GETPOST('effectif_id', 'int');
$object->typent_id = GETPOST('typent_id','int'); $object->typent_id = GETPOST('typent_id','int');
$object->typent_code = dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type $object->typent_code = dol_getIdFromCode($db, $object->typent_id, 'c_typent', 'id', 'code'); // Force typent_code too so check in verify() will be done on new type
$object->client = GETPOST('client', 'int'); $object->client = GETPOST('client', 'int');
$object->fournisseur = GETPOST('fournisseur', 'int'); $object->fournisseur = GETPOST('fournisseur', 'int');
$object->commercial_id = GETPOST('commercial_id', 'int'); $object->commercial_id = GETPOST('commercial_id', 'int');
$object->default_lang = GETPOST('default_lang'); $object->default_lang = GETPOST('default_lang');
// Webservices url/key // Webservices url/key
$object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL); $object->webservices_url = GETPOST('webservices_url', 'custom', 0, FILTER_SANITIZE_URL);
$object->webservices_key = GETPOST('webservices_key', 'san_alpha'); $object->webservices_key = GETPOST('webservices_key', 'san_alpha');
// Incoterms // Incoterms
if (!empty($conf->incoterm->enabled)) if (!empty($conf->incoterm->enabled))
{ {
$object->fk_incoterms = GETPOST('incoterm_id', 'int'); $object->fk_incoterms = GETPOST('incoterm_id', 'int');
$object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
} }
// Multicurrency // Multicurrency
if (!empty($conf->multicurrency->enabled)) if (!empty($conf->multicurrency->enabled))
{ {
$object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
} }
// Fill array 'array_options' with data from add form // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) if ($ret < 0)
{ {
$error++; $error++;
$action = ($action=='add'?'create':'edit'); }
}
if (GETPOST('deletephoto')) $object->logo = ''; if (GETPOST('deletephoto')) $object->logo = '';
else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']);
// Check parameters // Check parameters
if (! GETPOST('cancel','alpha')) if (! GETPOST('cancel','alpha'))
{ {
if (! empty($object->email) && ! isValidEMail($object->email)) if (! empty($object->email) && ! isValidEMail($object->email))
{ {
$langs->load("errors"); $langs->load("errors");
$error++; $error++;
setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors'); setEventMessages('', $langs->trans("ErrorBadEMail",$object->email), 'errors');
$action = ($action=='add'?'create':'edit'); }
} if (! empty($object->url) && ! isValidUrl($object->url))
if (! empty($object->url) && ! isValidUrl($object->url)) {
{ $langs->load("errors");
$langs->load("errors"); setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors');
setEventMessages('', $langs->trans("ErrorBadUrl",$object->url), 'errors'); }
$action = ($action=='add'?'create':'edit'); if ($object->fournisseur && ! $conf->fournisseur->enabled)
} {
if ($object->fournisseur && ! $conf->fournisseur->enabled) $langs->load("errors");
{ setEventMessages('', $langs->trans("ErrorSupplierModuleNotEnabled"), 'errors');
$langs->load("errors"); }
setEventMessages('', $langs->trans("ErrorSupplierModuleNotEnabled"), 'errors'); if (! empty($object->webservices_url)) {
$action = ($action=='add'?'create':'edit'); //Check if has transport, without any the soap client will give error
} if (strpos($object->webservices_url, "http") === false)
if (! empty($object->webservices_url)) { {
//Check if has transport, without any the soap client will give error $object->webservices_url = "http://".$object->webservices_url;
if (strpos($object->webservices_url, "http") === false) }
{ if (! isValidUrl($object->webservices_url)) {
$object->webservices_url = "http://".$object->webservices_url; $langs->load("errors");
} $error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
if (! isValidUrl($object->webservices_url)) { }
$langs->load("errors"); }
$error++; $errors[] = $langs->trans("ErrorBadUrl",$object->webservices_url);
$action = ($action=='add'?'create':'edit');
}
}
// We set country_id, country_code and country for the selected country // We set country_id, country_code and country for the selected country
$object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id; $object->country_id=GETPOST('country_id')!=''?GETPOST('country_id'):$mysoc->country_id;
if ($object->country_id) if ($object->country_id)
{ {
$tmparray=getCountry($object->country_id,'all'); $tmparray=getCountry($object->country_id,'all');
$object->country_code=$tmparray['code']; $object->country_code=$tmparray['code'];
$object->country=$tmparray['label']; $object->country=$tmparray['label'];
} }
}
} }
if (! $error) if (! $error)