Change validation order of menu item fields
authorMatthias Schmidt <gravatronics@live.com>
Sun, 31 Jul 2016 16:15:37 +0000 (18:15 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 31 Jul 2016 16:15:37 +0000 (18:15 +0200)
Fields should generally be validated in the order in which they are
presented to the user.

wcfsetup/install/files/lib/acp/form/MenuItemAddForm.class.php

index 3023d99b0fd20048a141d3472367b7e12560e84b..3cc0b313653d523c2fe36ab9c841a14805f80eb3 100644 (file)
@@ -166,6 +166,24 @@ class MenuItemAddForm extends AbstractForm {
        public function validate() {
                parent::validate();
                
+               // validate parent menu item
+               if ($this->parentItemID) {
+                       $parentMenuItem = new MenuItem($this->parentItemID);
+                       if (!$parentMenuItem->itemID || $parentMenuItem->menuID != $this->menuID) {
+                               throw new UserInputException('parentItemID', 'invalid');
+                       }
+               }
+               
+               // validate page menu item name
+               if (!I18nHandler::getInstance()->validateValue('title')) {
+                       if (I18nHandler::getInstance()->isPlainValue('title')) {
+                               throw new UserInputException('title');
+                       }
+                       else {
+                               throw new UserInputException('title', 'multilingual');
+                       }
+               }
+               
                // validate menu item controller
                if ($this->isInternalLink) {
                        $this->externalURL = '';
@@ -199,24 +217,6 @@ class MenuItemAddForm extends AbstractForm {
                                throw new UserInputException('externalURL');
                        }
                }
-               
-               // validate page menu item name
-               if (!I18nHandler::getInstance()->validateValue('title')) {
-                       if (I18nHandler::getInstance()->isPlainValue('title')) {
-                               throw new UserInputException('title');
-                       }
-                       else {
-                               throw new UserInputException('title', 'multilingual');
-                       }
-               }
-               
-               // validate parent menu item
-               if ($this->parentItemID) {
-                       $parentMenuItem = new MenuItem($this->parentItemID);
-                       if (!$parentMenuItem->itemID || $parentMenuItem->menuID != $this->menuID) {
-                               throw new UserInputException('parentItemID', 'invalid');
-                       }
-               }
        }
        
        /**