Umbraco Forms functionality can be extended in various ways. In this section we focus on techniques available to a back-end/C# developer.
Although the Forms package comes with many fields, workflows and other built-in types, you can still create and develop your own if needed.
Many features of Forms use a provider model, which makes it quicker to add new parts to the application.
The model uses the notion that everything must have a type to exist. The type defines the capabilities of the item. For instance a Textfield on a form has a FieldType, this particular field type enables it to render an input field and save text strings. The same goes for workflows, which have a workflow type, datasources which have a datasource type and so on. Using the model you can seamlessly add new types and thereby extend the application.
It is possible to add new Field types, Data Source Types, Prevalue Source Types, Export Types, and Workflow Types.
A field type handles rendering of the UI for a field in a form. It renders a standard ASP.NET webcontrol and is able to return a list of values when the form is saved.
The concept of provider settings, common to the field and other types, is also discussed in this section.
A data source type enables Umbraco Forms to connect to a custom source of data. A data source consists of any kind of storage if it is possible to return a list of fields Umbraco Forms can map values to. For example: a Database data source can return a list of columns Forms can send data to. This enables Umbraco Forms to map a form to a data source. A data source type is responsible for connecting Forms to external storage.
A prevalue source type can connect to a 3rd party storage and retrieve a collection of values that can be used on fields that support prevalues. The prevalue source is responsible for connecting to the source and retrieving the collection of values.
A workflow can be executed each time a form changes state (when it is submitted for instance). A workflow is responsible for executing logic which can modify the record or notify 3rd party systems.
Export types are responsible for turning form records into any other data format, which is then returned as a file.
Custom magic string format functions to add to the ones shipped with Umbraco Forms can be created in code.
When creating a text field in Umbraco Forms, a validation pattern in the form of a regular expression can be applied. Default patterns can be removed or re-ordered, and custom ones created and added.
Another option for extension via custom code is to hook into one of the many events available.
Form events are raised during the submission life cycle and can be handled for executing custom logic.
The default behavior when a new form is created is for a single workflow to be added, which will send a copy of the form to the current backoffice user's email address.
It's been possible to amend this behavior and change it to fit your needs.
In the course of submitting a form, Umbraco Forms will set various values in
HttpContext.Items, that you can use to customize the website functionality.
Whether displaying a message or redirecting, a developer can customize the page viewed after the form is submitted based on the presence of
One variable with a key of
UmbracoFormSubmittedhas a value containing the Guid identifier for the submitted form.
A second variable contains the Guid identifier of the record created from the form submission. You can find this using the
In order to redirect to an external URL rather than a selected page on the Umbraco website, you will need to use a custom workflow. Within this workflow you can set the required redirect URL on the
HttpContext.Itemsdictionary using the key
FormsRedirectAfterFormSubmitUrl(defined in the constant
For example, using an injected instance of
_httpContextAccessor.HttpContext.Items[Constants.ItemKeys.RedirectAfterFormSubmitUrl] = "https://www.umbraco.com";