- Added form name to allow for multiple form on the same page.
This commit is contained in:
parent
b1129def47
commit
23e8eb71f6
|
@ -214,7 +214,7 @@ class UiElement implements \ArrayAccess, \Iterator, \JsonSerializable {
|
||||||
|
|
||||||
if ( $this->options['tag-type'] ?? false ) {
|
if ( $this->options['tag-type'] ?? false ) {
|
||||||
if ( $this->options['tag-type'] === "single" ) {
|
if ( $this->options['tag-type'] === "single" ) {
|
||||||
return $opentag . $content;
|
$closetag = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ( in_array('force-tag-close', $this->options) ) {
|
elseif ( in_array('force-tag-close', $this->options) ) {
|
||||||
|
|
|
@ -7,6 +7,8 @@ use Psr\Http\Message\ServerRequestInterface,
|
||||||
|
|
||||||
class FormContext implements FormContextInterface
|
class FormContext implements FormContextInterface
|
||||||
{
|
{
|
||||||
|
public string $formName;
|
||||||
|
|
||||||
public bool $formSent;
|
public bool $formSent;
|
||||||
|
|
||||||
public array $values = [];
|
public array $values = [];
|
||||||
|
@ -17,9 +19,14 @@ class FormContext implements FormContextInterface
|
||||||
|
|
||||||
public ? ResponseInterface $response = null;
|
public ? ResponseInterface $response = null;
|
||||||
|
|
||||||
public function __construct(ServerRequestInterface $request)
|
public function __construct(ServerRequestInterface $request, ? string $formName = null)
|
||||||
{
|
{
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
|
||||||
|
if ( $formName ) {
|
||||||
|
$this->formName = $formName;
|
||||||
|
}
|
||||||
|
|
||||||
$this->values = $request->getParsedBody() ?: [];
|
$this->values = $request->getParsedBody() ?: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +45,7 @@ class FormContext implements FormContextInterface
|
||||||
{
|
{
|
||||||
return $this->formSent;
|
return $this->formSent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __set($key, $value)
|
public function __set($key, $value)
|
||||||
{
|
{
|
||||||
return $this->set($key, $value);
|
return $this->set($key, $value);
|
||||||
|
|
|
@ -25,10 +25,19 @@ class FormHandler {
|
||||||
else {
|
else {
|
||||||
$this->context = method_exists($form, 'getContext') ? $form->getContext($request) : new FormContext($request);
|
$this->context = method_exists($form, 'getContext') ? $form->getContext($request) : new FormContext($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->context->formSent = $this->sent;
|
$this->formSent();
|
||||||
$this->initialize();
|
$this->initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function formSent() : void
|
||||||
|
{
|
||||||
|
if ( false !== $this->context->formSent = $this->sent ) {
|
||||||
|
if ( $this->context->formName ?? false ) {
|
||||||
|
$this->context->formSent = (bool) ( $this->request->getParsedBody()['picea-ui-form'][$this->context->formName] ?? false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function initialize() : void
|
protected function initialize() : void
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue