From 657ceb28638defddc461de1115cfe14821f9cc4f Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Mon, 17 Feb 2020 08:17:36 -0500 Subject: [PATCH] - Added multi-part by default to forms - Fixed some bug within FormContext and FormHandler. --- src/Form/UiForm.php | 4 +++- src/Form/UiTel.php | 5 +++-- src/Method/Form.php | 4 +--- src/Method/FormContext.php | 4 +--- src/Method/FormHandler.php | 2 -- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Form/UiForm.php b/src/Form/UiForm.php index 77119c0..a0b74c0 100644 --- a/src/Form/UiForm.php +++ b/src/Form/UiForm.php @@ -55,11 +55,13 @@ class UiForm extends UiElement implements Extension { $method = strtolower($method); $this->option('tag-type', 'single'); + $this->attributes([ 'method' => $method, 'action' => $action ] + $attributes); if ( $method !== "get" ) { $this->append( ( new UiHidden() )->attributes([ 'name' =>"picea-csrf-protection", 'value' => "abcdefg" ]) ); - } + $this->attributes([ 'enctype' => "multipart/form-data" ]); + } return $this->render() . PHP_EOL; } diff --git a/src/Form/UiTel.php b/src/Form/UiTel.php index 22f3c1c..754192a 100644 --- a/src/Form/UiTel.php +++ b/src/Form/UiTel.php @@ -10,8 +10,9 @@ class UiTel extends UiInput { 'class' => "ui-tel", 'type' => "tel", ]; - - public string $defaultPattern = "[0-9]{1}-[0-9]{3}-[0-9]{3}-[0-9]{4}"; + + # Optional dashes and/or spaces in phone + public string $defaultPattern = "[0-9]{1}[ -]?[0-9]{3}[ -]?[0-9]{3}[ -]?[0-9]{4}"; protected function parseAttributes(?string $options) : array { diff --git a/src/Method/Form.php b/src/Method/Form.php index 2d8ca66..0f6a253 100644 --- a/src/Method/Form.php +++ b/src/Method/Form.php @@ -29,8 +29,6 @@ class Form implements Extension { public function register(Context $context) : void { - $this->formContext = new FormContext($this->request); - $context->pushFunction("form", [ $this, 'formClass' ]); } @@ -52,6 +50,6 @@ class Form implements Extension { public function formClass(FormInterface $form, ? FormContext $formContext = null) : FormHandler { - return new FormHandler($this->request, $form, $formContext ?: $this->formContext); + return new FormHandler($this->request, $form, $formContext ?? $this->formContext ?? null); } } diff --git a/src/Method/FormContext.php b/src/Method/FormContext.php index 565d272..4d1d22d 100644 --- a/src/Method/FormContext.php +++ b/src/Method/FormContext.php @@ -17,8 +17,6 @@ class FormContext implements FormContextInterface public ? ResponseInterface $response = null; - protected int $action; - public function __construct(ServerRequestInterface $request) { $this->request = $request; @@ -68,7 +66,7 @@ class FormContext implements FormContextInterface public function set(string $key, $value) { - return $_SESSION[$key] = $value; + return $this->values[$key] = $value; } public function delete(string $key) : void diff --git a/src/Method/FormHandler.php b/src/Method/FormHandler.php index 7edea9c..219add9 100644 --- a/src/Method/FormHandler.php +++ b/src/Method/FormHandler.php @@ -5,8 +5,6 @@ namespace Picea\Ui\Method; use Psr\Http\Message\ServerRequestInterface; class FormHandler { - # return new class($this->request, new FormContext(), $form) { - public bool $sent = false; public FormContext $context;