- 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'] === "single" ) { | ||||
|                     return $opentag . $content; | ||||
|                     $closetag = ""; | ||||
|                 } | ||||
|             } | ||||
|             elseif ( in_array('force-tag-close', $this->options) ) { | ||||
|  | ||||
| @ -7,6 +7,8 @@ use Psr\Http\Message\ServerRequestInterface, | ||||
| 
 | ||||
| class FormContext implements FormContextInterface | ||||
| { | ||||
|     public string $formName; | ||||
|      | ||||
|     public bool $formSent; | ||||
|      | ||||
|     public array $values = []; | ||||
| @ -17,9 +19,14 @@ class FormContext implements FormContextInterface | ||||
|      | ||||
|     public ? ResponseInterface $response = null; | ||||
| 
 | ||||
|     public function __construct(ServerRequestInterface $request)  | ||||
|     public function __construct(ServerRequestInterface $request, ? string $formName = null)  | ||||
|     { | ||||
|         $this->request = $request; | ||||
|          | ||||
|         if ( $formName ) { | ||||
|             $this->formName = $formName;         | ||||
|         } | ||||
|          | ||||
|         $this->values = $request->getParsedBody() ?: []; | ||||
|     } | ||||
|      | ||||
|  | ||||
| @ -26,10 +26,19 @@ class FormHandler { | ||||
|             $this->context = method_exists($form, 'getContext') ? $form->getContext($request) : new FormContext($request); | ||||
|         } | ||||
|          | ||||
|         $this->context->formSent = $this->sent; | ||||
|         $this->formSent(); | ||||
|         $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 | ||||
|     { | ||||
|         $this->form->initialize($this->context); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user