Accelerator 6.4.0 introduces a new CMS feature: AB_GeneralForm. This feature allows simple forms to be added to CMS website pages with a div tag and data attributes, similar to the way Bootstrap Javascript plugins work. Some form types are available in Accelerator and others can be added by the website project; the form type defines a set of available fields and their validation rules using standard DataAnnotations
property attributes. The CMS page markup decares which fields to use, their order, and whether or not they are required. It also declares actions to take when the form is submitted: send an email to the user, send an internal email, create a workflow instance, redirect to a different CMS page, unhide an element on the page and insert a message into it.
In the CMS page:
<div data-a4dn-general-form="contact-info" data-a4dn-fields="*FirstName,*LastName,*Email,Company,Title,Phone,Address,*Message" data-a4dn-display-template="bs-form-icons" data-a4dn-requestor-mandrill-template="..." data-a4dn-internal-mandrill-template="..." data-a4dn-workflow-namespace="..." data-a4dn-confirmation-modulenumber="..." data-a4dn-show-on-success="..." data-a4dn-show-on-error="..." data-a4dn-submit-label="..." ></div>
This element's content will be populated with the "contact-info" form, rendered using ~/Views/AB_GeneralForm/bs-form-icons.cshtml
, and only showing the fields listed in data-a4dn-fields
. Any field names prefixed with *
will be required. If submit-label
is provided, it will override the label on the Submit button.
NOTE: Currently, a CMS page can only contain one element like this at a time. Support for multiple forms on a page is planned for a later release.
- a4dn-general-form: The value "contact-info" gets mapped to the C# model class that has properties for all of the available fields for this form type. Website projects can define their own types and add them to the mapping list.
- a4dn-fields: A comma-separated list of the fields to show, prefixed by * if they are requried. The field names match the C# property names, Mandrill merge tag names, and Workflow custom field namespaces.
- a4dn-display-template: The name of the Razor template used to render the model. This allows different form styles to be used with the same model / form type. Website projects can provide their own templates.
- a4dn-requestor-mandrill-template: Optional. If provided the form data will be emailed to the user using the specified Mandrill template. The model class must specify which form field to use for the user's email address and name; therefore not all form types support emailing the user.
- a4dn-internal-mandrill-template: Optional. If provided the form data will be emailed to a configured email address using the specified Mandrill template. The website project's web.config file must contain an AB_GeneralForm.InternalEmail setting.
- a4dn-workflow-namespace: Optional. If specified a new Workflow Instance will be created for the given workflow. The model class can populate the instance name with any of the form fields.
- a4dn-confirmation-modulenumber: Optional. If specified a successful form submission will cause the browser to load the CMS page for the given module number.
- a4dn-show-on-success: Optional. If specified the value should be a selector expression for a hidden element to show after successfully submitting the form. If the element contains an element with class a4dn-js-message, it's content will be set to the success message returned by the server.
- a4dn-show-on-error: Optional. If specified this works like show-on-success, except for non-validation error messages when the form submission fails. (Eg: failure to send an email.)
- a4dn-submit-label: Optional. The label for the submit button; defaults to Submit (or whatever the display template chooses to use.)
- a4dn-{fieldname}: Optional. To override the label and placeholder text for a field, add a data attribute named a4dn- and the fieldname in lowercase. (Don't include the * for required fields.) The value of the attribute should be the label, a | character, and the placeholder text.
- a4dn-{fieldname}-options: Optional. Specifies allowed values for the field, which will be rendered as a dropdown select control. The attribute value can be either a comma-separated list or the id or name of a Property Code table.
confirmation-modulenumber cannot be used with show-on-success; use one or the other.
If show-on-error is not specified, or if it is specified but the element selector does not locate an element, then errors will be displayed in a Javascript Alert popup dialog.
If confirmation-modulenumber is not specified, and show-on-success is either not specified or the selector doesn't locate an element, then the success message returned by the server will be shown in a Javascript Alert popup dialog.