]> _ Git - cubist_cms-back.git/commitdiff
wip #5093 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 14 Feb 2022 18:14:09 +0000 (19:14 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 14 Feb 2022 18:14:09 +0000 (19:14 +0100)
src/app/Magic/Form.php
src/resources/views/form/form.blade.php

index de3b7125407a8649299f2a34c5b1401391f25084..8ddf68bc519e34158a803c5351e3f4a836b6bfce 100644 (file)
@@ -16,6 +16,8 @@ class Form extends SubForm
     protected $_enctype = 'application/x-www-form-urlencoded';
     protected $_csrf = true;
     protected $_title = '';
+    protected $_submitLabel = 'save';
+    protected $_submitIcon='la-save';
     protected $crud;
 
     public function __construct($action = '', $method = 'post')
@@ -23,7 +25,7 @@ class Form extends SubForm
         $this->setAction($action);
         $this->setMethod($method);
         $this->crud = new CubistCrudPanel();
-        $this->crud->model=new CubistMagicAbstractModel();
+        $this->crud->model = new CubistMagicAbstractModel();
         parent::__construct();
 
     }
@@ -87,7 +89,17 @@ class Form extends SubForm
      */
     public function setMethod(string $method): void
     {
-        $this->_method = $method;
+        $this->_method = mb_strtolower($method);
+    }
+
+    public function getSafeMethod()
+    {
+        $safe = ['get', 'post'];
+        $m = $this->getMethod();
+        if (in_array($m, $safe)) {
+            return $m;
+        }
+        return 'post';
     }
 
     /**
@@ -140,6 +152,38 @@ class Form extends SubForm
         return $field;
     }
 
+    /**
+     * @return string
+     */
+    public function getSubmitLabel(): string
+    {
+        return $this->_submitLabel;
+    }
+
+    /**
+     * @param string $submitLabel
+     */
+    public function setSubmitLabel(string $submitLabel): void
+    {
+        $this->_submitLabel = $submitLabel;
+    }
+
+    /**
+     * @return string
+     */
+    public function getSubmitIcon(): string
+    {
+        return $this->_submitIcon;
+    }
+
+    /**
+     * @param string $submitIcon
+     */
+    public function setSubmitIcon(string $submitIcon): void
+    {
+        $this->_submitIcon = $submitIcon;
+    }
+
     public function getAutoFocusOnFirstField()
     {
         return true;
index 9649ef8583c993a9f596bd9186b151629f39379f..005203f1d591f77ecf5c35bf4f209abebe2e1430 100644 (file)
@@ -4,5 +4,14 @@
 @endphp
 
 <h2>{{$form->getTitle()}}</h2>
-
-@include('crud::form_content')
+<form action="{{$form->getAction()}}" enctype="{{$form->getEnctype()}}" method="{{$form->getSafeMethod()}}">
+    <input type="hidden" name="_method" value="{{$form->getMethod()}}">
+    @if($form->isCsrf())
+        @csrf
+    @endif
+    @include('crud::form_content')
+    <button type="submit" class="btn btn-success">
+        <span class="la {{$form->getSubmitIcon()}}" role="presentation" aria-hidden="true"></span> &nbsp;
+        <span data-value="save_and_back">{{$form->getSubmitLabel()}}</span>
+    </button>
+</form>