diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php index c0e1b40..b35e925 100644 --- a/app/classes/Framadate/Form.php +++ b/app/classes/Framadate/Form.php @@ -41,6 +41,7 @@ class Form public $choix_sondage; public $ValueMax; + public $errors = []; /** * Tells if users can modify their choices. diff --git a/app/classes/Framadate/Services/PollService.php b/app/classes/Framadate/Services/PollService.php index 834001a..ca9eb70 100644 --- a/app/classes/Framadate/Services/PollService.php +++ b/app/classes/Framadate/Services/PollService.php @@ -216,16 +216,24 @@ class PollService { list($poll_id, $admin_poll_id) = $this->createPoll($form); // Send confirmation by mail if enabled - // Everything went well - $this->notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id); + if (!is_null($ids)) { + // Everything went well + $this->notificationService->sendPollCreationMails($form->admin_mail, $form->admin_name, $form->title, $poll_id, $admin_poll_id); - // Clean Form data in session - $this->sessionService->removeAll('form'); - // Creation message - $this->sessionService->set("Framadate", "messagePollCreated", TRUE); - - // Delete old polls - $this->purgeService->repeatedCleanings(); + // Clean Form data in session + $this->sessionService->removeAll('form'); + // Creation message + $this->sessionService->set("Framadate", "messagePollCreated", TRUE); + // Delete old polls + $this->purgeService->repeatedCleanings(); + } else { + // Add an error in the form + $form->errors = [ + __('Error', 'GenericErrorPollCreation') + ]; + // TODO: change this to use sessionService function + $_SESSION['form'] = serialize($form); + } return $admin_poll_id; } diff --git a/create_classic_poll.php b/create_classic_poll.php index b00835e..941f782 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -56,7 +56,7 @@ if (!isset($form->title) || !isset($form->admin_name) || ($config['use_smtp'] && $step = 1; } elseif (isset($_POST['confirmation'])) { $step = 4; -} elseif (empty($_POST['fin_sondage_autre']) ) { +} elseif (empty($form->errors) && empty($_POST['fin_sondage_autre']) ) { $step = 2; } else { $step = 3; @@ -137,6 +137,7 @@ switch ($step) { $smarty->assign('end_date_str', $end_date_str); $smarty->assign('default_poll_duration', $config['default_poll_duration']); $smarty->assign('use_smtp', $config['use_smtp']); + $smarty->assign('errors', $form->errors); $smarty->display('create_poll_step_3.tpl'); exit; @@ -152,6 +153,10 @@ switch ($step) { if (!is_null($admin_poll_id)) { // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); + } else { + // Redirect to current page + $referer = $_SERVER['HTTP_REFERER']; + header("Location: $referer"); } exit; diff --git a/create_date_poll.php b/create_date_poll.php index a1af888..cdd78a9 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -54,7 +54,7 @@ if (!isset($form->title) || !isset($form->admin_name) || ($config['use_smtp'] && $step = 1; } else if (!empty($_POST['confirmation'])) { $step = 4; -} else if (empty($_POST['choixheures']) || isset($form->totalchoixjour)) { +} else if (empty($form->errors) && (empty($_POST['choixheures']) || isset($form->totalchoixjour))) { $step = 2; } else { $step = 3; @@ -173,6 +173,7 @@ switch ($step) { $smarty->assign('end_date_str', $end_date_str); $smarty->assign('default_poll_duration', $config['default_poll_duration']); $smarty->assign('use_smtp', $config['use_smtp']); + $smarty->assign('errors', $form->errors); $smarty->display('create_poll_step_3.tpl'); exit; @@ -188,6 +189,10 @@ switch ($step) { if (!is_null($admin_poll_id)) { // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); + } else { + // Redirect to current page + $referer = $_SERVER['HTTP_REFERER']; + header("Location: $referer"); } exit; diff --git a/po/en.po b/po/en.po index a2bbd33..7114163 100755 --- a/po/en.po +++ b/po/en.po @@ -548,6 +548,10 @@ msgstr "Failed to save poll" msgid "Forbidden!" msgstr "Forbidden!" +#: .Error.GenericErrorPollCreation +msgid "GenericErrorPollCreation" +msgstr "Oh no! Your poll could not be created at the moment. Sorry about that. Please try again later." + #: .Error.Identifier+is+already+used msgid "Identifier is already used" msgstr "Identifier is already used" @@ -1920,4 +1924,3 @@ msgid "" msgstr "" "Your vote has been saved, but please note: you need to keep this " "personalised link to be able to edit your vote." - diff --git a/tpl/create_poll_step_3.tpl b/tpl/create_poll_step_3.tpl index 3e650a6..02ce0bc 100644 --- a/tpl/create_poll_step_3.tpl +++ b/tpl/create_poll_step_3.tpl @@ -38,6 +38,13 @@

{__('Step 3', 'Then you will receive two emails: one containing the link of your poll for sending to the participants, the other containing the link to the poll administration page.')}

{/if} + {if !empty($errors)} +
+ {foreach $errors as $error} +

{$error}

+ {/foreach} +
+ {/if}