From 7c920308acda0ff2a1b1cb6667af6ea2edfca67a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 14 Feb 2022 19:14:09 +0100 Subject: [PATCH] wip #5093 @0.5 --- src/app/Magic/Form.php | 48 +++++++++++++++++++++++-- src/resources/views/form/form.blade.php | 13 +++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/app/Magic/Form.php b/src/app/Magic/Form.php index de3b712..8ddf68b 100644 --- a/src/app/Magic/Form.php +++ b/src/app/Magic/Form.php @@ -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; diff --git a/src/resources/views/form/form.blade.php b/src/resources/views/form/form.blade.php index 9649ef8..005203f 100644 --- a/src/resources/views/form/form.blade.php +++ b/src/resources/views/form/form.blade.php @@ -4,5 +4,14 @@ @endphp

{{$form->getTitle()}}

- -@include('crud::form_content') +
+ + @if($form->isCsrf()) + @csrf + @endif + @include('crud::form_content') + +
-- 2.39.5