m (Text replacement - "{{Doc properties" to "{{Csp class properties") |
|||
(11 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | FlexForm can be extended by a PHP function to handle additional tasks after a Form has been submitted. | + | '''FlexForm''' can be extended by a PHP function to handle additional tasks after a Form has been submitted. |
− | |||
− | + | This can be done with '''FFAfterFormHandling''' MediaWiki Hook. For more information see de Docs on Hooks. | |
− | namespace FlexForm\Modules\Handlers\<your extension name = same as folder name>; | + | |
+ | Or using the following method: | ||
+ | |||
+ | Start a FlexForm and tell it to use your extension :<syntaxhighlight lang="html"> | ||
+ | <_form action="addToWiki" extension="<name of your extension" > | ||
+ | Your flexform elements here | ||
+ | </_form> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Create a folder in <code>FlexForm/src/Modules/Handlers</code> with the name of your extension. | ||
+ | |||
+ | In this folder create a file called <code>PostHandler.php</code> with the following namespace : | ||
+ | <syntaxhighlight lang="html"> | ||
+ | namespace FlexForm\Modules\Handlers\< your extension name = same as folder name >; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Your extension will be based based on a class PostHandler and will utilize the '''HandlerInterface''' interface and will only hold one method : '''execute''' | ||
+ | |||
+ | <syntaxhighlight lang="php"> | ||
+ | class PostHandler implements HandlerInterface { | ||
+ | /** | ||
+ | * @inerhitDoc | ||
+ | */ | ||
+ | public function execute( array $flexFormFields, HandleResponse $responseHandler ): HandleResponse { | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | The array <code>$flexFormFields</code> will be available and hold all submitted Form elements as '''name->value'''. | ||
+ | |||
+ | If your extension produces an error, throw a '''FlexFormException''' and FlexForm will take care of the rest. ''Make sure to throw a message that with your extension name''. | ||
+ | |||
+ | If your extension has successfully finished its tasks, tell the '''responsehandler''' it has been successful and return the responseHandler : | ||
+ | <syntaxhighlight lang="php"> | ||
+ | $responseHandler->setReturnType( HandleResponse::TYPE_SUCCESS ); | ||
+ | return $responseHandler; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | If your extension has successfully finished its tasks and you want to pass additional information to the user : | ||
+ | <syntaxhighlight lang="php"> | ||
+ | $responseHandler->setReturnType( HandleResponse::TYPE_SUCCESS ); | ||
+ | $responseHandler->setReturnData( string < your message > ); | ||
+ | return $responseHandler; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== NOTE: ==== | ||
+ | When a FlexForm has the extension tag. FlexForm will first search for the extension in the Handlers folder. If it cannot be found it will run the '''FFAfterFormHandling''' hook. | ||
+ | |||
+ | No error message will be shown if FlexForm cannot find the extension. | ||
ws-class-props | |||
---|---|---|---|
Line 1: | Line 1: | ||
− | + | {{Csp class properties | |
+ | |Doc subject=DevOps:Doc/FlexForm | ||
+ | |Subject version=1.1 | ||
+ | |Doc parent= | ||
+ | |Doc sort order=250 | ||
+ | |Doc target group=Developer | ||
+ | |Doc synopsis=Creating a FlexForm extension | ||
+ | }} | ||
ws-page-props | |||
Line 1: | Line 1: | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− |
Latest revision as of 11:00, 15 July 2025
FlexForm can be extended by a PHP function to handle additional tasks after a Form has been submitted.
This can be done with FFAfterFormHandling MediaWiki Hook. For more information see de Docs on Hooks.
Or using the following method:
Start a FlexForm and tell it to use your extension :
<_form action="addToWiki" extension="<name of your extension" >
Your flexform elements here
</_form>
Create a folder in FlexForm/src/Modules/Handlers
with the name of your extension.
In this folder create a file called PostHandler.php
with the following namespace :
namespace FlexForm\Modules\Handlers\< your extension name = same as folder name >;
Your extension will be based based on a class PostHandler and will utilize the HandlerInterface interface and will only hold one method : execute
class PostHandler implements HandlerInterface {
/**
* @inerhitDoc
*/
public function execute( array $flexFormFields, HandleResponse $responseHandler ): HandleResponse {
}
}
The array $flexFormFields
will be available and hold all submitted Form elements as name->value.
If your extension produces an error, throw a FlexFormException and FlexForm will take care of the rest. Make sure to throw a message that with your extension name.
If your extension has successfully finished its tasks, tell the responsehandler it has been successful and return the responseHandler :
$responseHandler->setReturnType( HandleResponse::TYPE_SUCCESS );
return $responseHandler;
If your extension has successfully finished its tasks and you want to pass additional information to the user :
$responseHandler->setReturnType( HandleResponse::TYPE_SUCCESS );
$responseHandler->setReturnData( string < your message > );
return $responseHandler;
NOTE:
When a FlexForm has the extension tag. FlexForm will first search for the extension in the Handlers folder. If it cannot be found it will run the FFAfterFormHandling hook.
No error message will be shown if FlexForm cannot find the extension.