From b2ae2a7b3036b0854eeab89bc99da813b5a8376b Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 8 Aug 2015 11:54:50 +0200 Subject: [PATCH] Show error message if poll has no question --- CHANGELOG.md | 1 + .../templates/__messageFormPoll.tpl | 5 +++++ .../lib/system/poll/PollManager.class.php | 19 ++++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e12500a0..6f5e221468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,3 +33,4 @@ * Overhauled Redactor integration * Linebreaks mode instead of using paragraphs, works better with the PHP-side parser which works with linebreaks * Ported the PHP-BBCode parser, massively improves accuracy and ensures validity +* Show error message if poll options are given but not question instead of discarding poll options. diff --git a/com.woltlab.wcf/templates/__messageFormPoll.tpl b/com.woltlab.wcf/templates/__messageFormPoll.tpl index 78a905e729..42aa7e7161 100644 --- a/com.woltlab.wcf/templates/__messageFormPoll.tpl +++ b/com.woltlab.wcf/templates/__messageFormPoll.tpl @@ -20,6 +20,11 @@
+ {if $errorField == 'pollQuestion'} + + {lang}wcf.global.form.error.empty{/lang} + + {/if}
diff --git a/wcfsetup/install/files/lib/system/poll/PollManager.class.php b/wcfsetup/install/files/lib/system/poll/PollManager.class.php index d8ef0ee515..285db1a878 100644 --- a/wcfsetup/install/files/lib/system/poll/PollManager.class.php +++ b/wcfsetup/install/files/lib/system/poll/PollManager.class.php @@ -197,11 +197,6 @@ class PollManager extends SingletonFactory { * Validates poll parameters. */ public function validate() { - // if no question is given, ignore poll completely - if (empty($this->pollData['question'])) { - return; - } - if ($this->pollData['endTime'] && $this->pollData['endTime'] <= TIME_NOW) { if ($this->poll === null || $this->poll->endTime >= TIME_NOW) { // end time is in the past @@ -209,9 +204,19 @@ class PollManager extends SingletonFactory { } } - // no options given $count = count($this->pollOptions); - if (!$count) { + if (empty($this->pollData['question'])) { + if ($count) { + // options given, but no question + throw new UserInputException('pollQuestion'); + } + else { + // if no question and no options are given, ignore poll completely + return; + } + } + else if (!$count) { + // no options given throw new UserInputException('pollOptions'); } -- 2.20.1