Browse Source

Fix bbcode validation

Visman 4 years ago
parent
commit
66cf3db14b
1 changed files with 14 additions and 6 deletions
  1. 14 6
      app/Models/Pages/Admin/Parser/BBCode.php

+ 14 - 6
app/Models/Pages/Admin/Parser/BBCode.php

@@ -301,18 +301,12 @@ class BBCode extends Parser
                     'def_attr.format'           => 'string:trim|max:1024',
                     'def_attr.body_format'      => 'string:trim|max:1024',
                     'def_attr.text_only'        => 'required|integer|in:0,1',
-                    'other_attrs.*.allowed'     => 'required|integer|in:0,1',
-                    'other_attrs.*.required'    => 'required|integer|in:0,1',
-                    'other_attrs.*.format'      => 'string:trim|max:1024',
-                    'other_attrs.*.body_format' => 'string:trim|max:1024',
-                    'other_attrs.*.text_only'   => 'required|integer|in:0,1',
                     'new_attr.name'             => ['string:trim', 'regex:%^(?:|[a-z-]{2,15})$%'],
                     'new_attr.allowed'          => 'required|integer|in:0,1',
                     'new_attr.required'         => 'required|integer|in:0,1',
                     'new_attr.format'           => 'string:trim|max:1024',
                     'new_attr.body_format'      => 'string:trim|max:1024',
                     'new_attr.text_only'        => 'required|integer|in:0,1',
-                    'save'                      => 'check_all',
                 ])->addAliases([
                 ])->addArguments([
                     'token'                    => $pageArgs,
@@ -320,6 +314,20 @@ class BBCode extends Parser
                 ])->addMessages([
                 ]);
 
+                if ($structure->other_attrs) {
+                    $v->addRules([
+                        'other_attrs.*.allowed'     => 'required|integer|in:0,1',
+                        'other_attrs.*.required'    => 'required|integer|in:0,1',
+                        'other_attrs.*.format'      => 'string:trim|max:1024',
+                        'other_attrs.*.body_format' => 'string:trim|max:1024',
+                        'other_attrs.*.text_only'   => 'required|integer|in:0,1',
+                    ]);
+                }
+
+                $v->addRules([
+                    'save' => 'check_all',
+                ]);
+
                 if ($v->validation($_POST)) {
                     if ($id > 0) {
                         $this->c->bbcode->update($id, $structure);