From 5fe0a2915338c3c5346bc5722ba385c3e9477daf Mon Sep 17 00:00:00 2001 From: Tim Schiewe Date: Tue, 7 Jun 2016 14:27:44 +0200 Subject: [PATCH] Fixed check for empty polls If the question was empty, the poll was discarded, even when the user gave options. This could lead to frustation as all options had to be typed again. --- com.woltlab.wcf/templates/__messageFormPoll.tpl | 9 ++++++++- .../files/lib/system/poll/PollManager.class.php | 12 +++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/com.woltlab.wcf/templates/__messageFormPoll.tpl b/com.woltlab.wcf/templates/__messageFormPoll.tpl index 78a905e729..9a2f7f90a9 100644 --- a/com.woltlab.wcf/templates/__messageFormPoll.tpl +++ b/com.woltlab.wcf/templates/__messageFormPoll.tpl @@ -14,13 +14,20 @@
- +
+ {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 dd7898374c..10b54d67f2 100644 --- a/wcfsetup/install/files/lib/system/poll/PollManager.class.php +++ b/wcfsetup/install/files/lib/system/poll/PollManager.class.php @@ -197,10 +197,17 @@ class PollManager extends SingletonFactory { * Validates poll parameters. */ public function validate() { - // if no question is given, ignore poll completely - if (empty($this->pollData['question'])) { + $count = count($this->pollOptions); + + // if no question and no options are given, ignore poll completely + if (empty($this->pollData['question']) && !$count) { return; } + + // no question given + if (empty($this->pollData['question'])) { + throw new UserInputException('pollQuestion'); + } if ($this->pollData['endTime'] && $this->pollData['endTime'] <= TIME_NOW) { if ($this->poll === null || $this->poll->endTime >= TIME_NOW) { @@ -210,7 +217,6 @@ class PollManager extends SingletonFactory { } // no options given - $count = count($this->pollOptions); if (!$count) { throw new UserInputException('pollOptions'); } -- 2.20.1