get((int) qg('id')); if (!$l) { throw new UserException("Cette localisation n'existe pas."); } $csrf_key = 'edit_location_' . $l->id; if (f('save') && $form->check($csrf_key) && !$form->hasErrors()) { try { $loc->edit($l->id, [ 'name' => ucfirst(f('name')) ]); Utils::redirect(PLUGIN_URL . 'localisations/index.php'); } catch (\RuntimeException $e) { if (strstr($e->getMessage(), 'UNIQUE constraint failed')) { $form->addError('Cette localisation existe déjà.'); } else { $form->addError($e->getMessage()); } } } $cancel_link = PLUGIN_URL . 'localisations/index.php'; $tpl->assign(compact('l', 'csrf_key', 'cancel_link')); $tpl->display(PLUGIN_ROOT . '/templates/localisations/modifier_localisation.tpl');