I'm using Sitecore 9, which has Sitecore Forms built-in out of the box. In the "Form Elements" tools panel on the right, there's a list of elements you can use to build the form. For example: Text, Single-line text, Multi-line text, Number, Email, etc. The Text element only allows plain text, although you can choose from a short list of html tags to wrap in it. It does not allow for rich text, such as adding anchor tags. How do you add rich text to the middle of a Sitecore Form?
1 Answer
You could check the Forms Extension my colleague Bart released: https://github.com/bartverdonck/Sitecore-Forms-Extensions. It includes a "RawHtml" field that can be used to output unescaped pure html.
Or just check that code to create your own version with a custom field that suits your needs (as the raw html is fairly simple). Documentation on how to create your custom field can be found here: https://doc.sitecore.com/en/developers/90/sitecore-experience-manager/walkthrough--creating-a-custom-form-element.html
Overview of the steps (from the Walkthrough)
To build a custom form element, you need these essential steps:
- Create a new field template (Base template is
Templates/System/Forms/Fields/Field
) - Create a new class that derives from the FieldViewModel class (for Simple field types such as an integer field or a multi-line text field ) or from the ListViewModel class (for List field types such as a drop-down list).
- Create a razor view file that will provide the CSHTML markup that will use your view model.
- Create the sections for the Form elements pane. Suggestion in the docs is to use Sitecore Rocks, navigate to
/sitecore/client/Applications/FormsBuilder/Components/Layouts/PropertyGridForm/PageSettings/Settings
and add a new item using theForm Parameters
template. You can then create the new sections using theFormSection
template and creating children of this new new Form Parameters item. - Configure the field editor parameters. For each of these new parameters you create, you'll need to set things like Styling, FormLabel, etc.
-
2Due to a duplicate question that was recommended to come here, I found out that this is a perfect example of a "link-only answer" that breaks down (unfortunately). It looks like the link to the walkthrough is no longer valid. I have tried to fix the URL and also provide some of the instructions in the body of the answer. Sep 14, 2021 at 11:30