Forráskód Böngészése

* Form refactoring 1

Visman 6 éve
szülő
commit
6731167d40
2 módosított fájl, 36 hozzáadás és 17 törlés
  1. 34 4
      app/Models/Pages/Rules.php
  2. 2 13
      app/templates/rules.forkbb.php

+ 34 - 4
app/Models/Pages/Rules.php

@@ -20,7 +20,6 @@ class Rules extends Page
         $this->title      = \ForkBB\__('Forum rules');
         $this->crumbs     = $this->crumbs([$this->c->Router->link('Rules'), \ForkBB\__('Forum rules')]);
         $this->rules      = $this->c->config->o_rules_message;
-        $this->formAction = null;
 
         return $this;
     }
@@ -41,10 +40,41 @@ class Rules extends Page
         $this->title      = \ForkBB\__('Forum rules');
         $this->crumbs     = $this->crumbs(\ForkBB\__('Forum rules'), [$this->c->Router->link('Register'), \ForkBB\__('Register')]);
         $this->rules      = $this->c->config->o_rules == '1' ? $this->c->config->o_rules_message : \ForkBB\__('If no rules');
-        $this->formAction = $this->c->Router->link('RegisterForm');
-        $this->formToken  = $this->c->Csrf->create('RegisterForm');
-        $this->formHash   = $this->c->Csrf->create('Register');
+        $this->form       = $this->formAgree();
 
         return $this;
     }
+
+    /**
+     * Подготавливает массив данных для формы
+     *
+     * @return array
+     */
+    protected function formAgree()
+    {
+        return [
+            'action' => $this->c->Router->link('RegisterForm'),
+            'hidden' => [
+                'token' => $this->c->Csrf->create('RegisterForm'),
+            ],
+            'sets'   => [
+                'agree' => [
+                    'fields' => [
+                        'agree' => [
+                            'type'    => 'checkbox',
+                            'label'   => \ForkBB\__('Agree'),
+                            'value'   => $this->c->Csrf->create('Register'),
+                        ],
+                    ],
+                ],
+            ],
+            'btns'   => [
+                'register' => [
+                    'type'      => 'submit',
+                    'value'     => \ForkBB\__('Register'),
+                    'accesskey' => 's',
+                ],
+            ],
+        ];
+    }
 }

+ 2 - 13
app/templates/rules.forkbb.php

@@ -18,20 +18,9 @@
     <section class="f-main f-rules">
       <h2>{!! $p->title !!}</h2>
       <div id="id-rules">{!! $p->rules !!}</div>
-@if ($p->formAction)
+@if ($form = $p->form)
       <div class="f-fdiv f-lrdiv">
-        <form class="f-form" method="post" action="{!! $p->formAction !!}">
-          <input type="hidden" name="token" value="{!! $p->formToken !!}">
-          <fieldset>
-            <dl>
-              <dt></dt>
-              <dd><label class="f-child2"><input type="checkbox" name="agree" value="{!! $p->formHash !!}" tabindex="1">{!! __('Agree') !!}</label></dd>
-            </dl>
-          </fieldset>
-          <p class="f-btns">
-            <input class="f-btn" type="submit" name="register" value="{!! __('Register') !!}" tabindex="2">
-          </p>
-        </form>
+    @include('layouts/form')
       </div>
 @endif
     </section>