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