Custom Form Handlers
Platformus.Forms extension offers the great forms features. You can describe your forms in the backend, and then render them and get user feedback on any frontend view. When user fills the form and clicks the :guilabel:`Submit` button, data is sent to a server and might be processed in any way you want. User input is handled by the implementations of the IFormHandler interface.
The selected implementation gets the form object, all the user input (string values by field objects), and all the attachments
user has uploaded. It can return any
IActionResult as the result.
Platformus has the only one built-in implementation of the
the EmailFormHandler class.
It sends the user input to the specified email recipients.
Let’s implement our own form handler, which will just display the user input. Create the
DisplayUserInputFormHandler class inside the main web application project
and implement the
IFormHandler interface there (in order to be able to write custom code in your Platformus-based web application, you can’t use Platformus
as the compiled executable; use it as the NuGet packages instead, or write your own extension project and then put its compiled DLL file inside the extensions folder):
As you can see, we used the FormHandlerBase
abstract class instead of implementing the
IFormHandler interface from scratch. It provides useful methods to manipulate the form handler parameters (see below).
Now, when our form handler class is added, navigate to the backend’s :guilabel:`Content/Forms` section and create or edit a form:
Please note, that our new form handler C# class is automatically resolved and added to the drop down list. Click the :guilabel:`Save` button.
Now navigate to /en/contacts and fill out the form:
Click the :guilabel:`Send` button. Output from our form handler is displayed:
We could return some view, redirect, or any other action result we need.
Form Handler Parameters and Parameter Groups
As well as the endpoints and data sources, form handlers support parameters and parameter groups. The implementation is absolutely the same, so please just take a look at the one for the endpoints. Also, please take a look at the built-in form handler to see how it uses this feature.