- Added multi-part by default to forms

- Fixed some bug within FormContext and FormHandler.
This commit is contained in:
Dave Mc Nicoll 2020-02-17 08:17:36 -05:00
parent 50d95defee
commit 657ceb2863
5 changed files with 8 additions and 11 deletions

View File

@ -55,11 +55,13 @@ class UiForm extends UiElement implements Extension {
$method = strtolower($method); $method = strtolower($method);
$this->option('tag-type', 'single'); $this->option('tag-type', 'single');
$this->attributes([ 'method' => $method, 'action' => $action ] + $attributes); $this->attributes([ 'method' => $method, 'action' => $action ] + $attributes);
if ( $method !== "get" ) { if ( $method !== "get" ) {
$this->append( ( new UiHidden() )->attributes([ 'name' =>"picea-csrf-protection", 'value' => "abcdefg" ]) ); $this->append( ( new UiHidden() )->attributes([ 'name' =>"picea-csrf-protection", 'value' => "abcdefg" ]) );
} $this->attributes([ 'enctype' => "multipart/form-data" ]);
}
return $this->render() . PHP_EOL; return $this->render() . PHP_EOL;
} }

View File

@ -10,8 +10,9 @@ class UiTel extends UiInput {
'class' => "ui-tel", 'class' => "ui-tel",
'type' => "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 protected function parseAttributes(?string $options) : array
{ {

View File

@ -29,8 +29,6 @@ class Form implements Extension {
public function register(Context $context) : void public function register(Context $context) : void
{ {
$this->formContext = new FormContext($this->request);
$context->pushFunction("form", [ $this, 'formClass' ]); $context->pushFunction("form", [ $this, 'formClass' ]);
} }
@ -52,6 +50,6 @@ class Form implements Extension {
public function formClass(FormInterface $form, ? FormContext $formContext = null) : FormHandler 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);
} }
} }

View File

@ -17,8 +17,6 @@ class FormContext implements FormContextInterface
public ? ResponseInterface $response = null; public ? ResponseInterface $response = null;
protected int $action;
public function __construct(ServerRequestInterface $request) public function __construct(ServerRequestInterface $request)
{ {
$this->request = $request; $this->request = $request;
@ -68,7 +66,7 @@ class FormContext implements FormContextInterface
public function set(string $key, $value) public function set(string $key, $value)
{ {
return $_SESSION[$key] = $value; return $this->values[$key] = $value;
} }
public function delete(string $key) : void public function delete(string $key) : void

View File

@ -5,8 +5,6 @@ namespace Picea\Ui\Method;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
class FormHandler { class FormHandler {
# return new class($this->request, new FormContext(), $form) {
public bool $sent = false; public bool $sent = false;
public FormContext $context; public FormContext $context;