Show error message if poll has no question
authorMatthias Schmidt <gravatronics@live.com>
Sat, 8 Aug 2015 09:54:50 +0000 (11:54 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 8 Aug 2015 09:54:50 +0000 (11:54 +0200)
CHANGELOG.md
com.woltlab.wcf/templates/__messageFormPoll.tpl
wcfsetup/install/files/lib/system/poll/PollManager.class.php

index 44e12500a0d5b47e023a11b0cfce525aebd17f2e..6f5e221468bbd7178f1c18b273321e5048fa2577 100644 (file)
@@ -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.
index 78a905e7294af87271acdea327a370cafac947f3..42aa7e716142aa4302f40b78688fd2f8cade5085 100644 (file)
                                </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>
                                <dt>
                                        <label>{lang}wcf.poll.options{/lang}</label>
index d8ef0ee515d9a143bba323ed9d70bdc3f12e1f78..285db1a878f39fb43d3feb7ae64946ba2288a581 100644 (file)
@@ -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');
                }