Fixed check for empty polls
authorTim Schiewe <schiewe31061@gmail.com>
Tue, 7 Jun 2016 12:27:44 +0000 (14:27 +0200)
committerTim Schiewe <schiewe31061@gmail.com>
Tue, 7 Jun 2016 12:27:44 +0000 (14:27 +0200)
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
wcfsetup/install/files/lib/system/poll/PollManager.class.php

index 78a905e7294af87271acdea327a370cafac947f3..9a2f7f90a9d64fb4bf555baedecb6001b3fe37a3 100644 (file)
        
        <div id="poll" class="jsOnly tabMenuContent container containerPadding">
                <fieldset>
-                       <dl{if $errorField == 'pollOptions'} class="formError"{/if}>
+                       <dl{if $errorField == 'pollQuestion'} class="formError"{/if}>
                                <dt>
                                        <label for="pollQuestion">{lang}wcf.poll.question{/lang}</label>
                                </dt>
                                <dd>
                                        <input type="text" name="pollQuestion" id="pollQuestion" value="{$pollQuestion}" class="long" maxlength="255" />
+                                       {if $errorField == 'pollQuestion'}
+                                               <small class="innerError">
+                                                       {lang}wcf.global.form.error.empty{/lang}
+                                               </small>
+                                       {/if}
                                </dd>
+                       </dl>
+                       <dl{if $errorField == 'pollOptions'} class="formError"{/if}>
                                <dt>
                                        <label>{lang}wcf.poll.options{/lang}</label>
                                </dt>
index dd7898374cde069b0bfa2476f7f693b6c9973e8f..10b54d67f217c83d202b684a7b9f06c3b13aa0af 100644 (file)
@@ -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');
                }