Traditionally, web forms are configured to submit synchronously. In synchronous submission, when users submit a form, they are redirected to an acknowledgment page, a thank you page, or in case of submission failure, an error page. However, modern web experiences like single page applications are gaining popularity where the web page remains static while client-server interaction happens in the background. You can configure asynchronous submission to provide this experience with Adaptive Forms.
In asynchronous submission, when a user submits a form the form developer plugs-in a separate experience like redirecting to other form or a separate section of the website. The author can also plug-in separate services like sending data to a different data store or adds a custom analytics engine. In case of asynchronous submission, an Adaptive Form behaves like a single page application as the form does not reload or its URL does not change when the submitted form data is validated on the server.
Read on for details about asynchronous submission in Adaptive Forms.
To configure asynchronous submission for an Adaptive Form:
In Adaptive Form authoring mode, select the Form Container object and tap to open its properties.
In the Submission properties section, enable Use asynchronous submission.
In the On Submit section, select one of the following options to perform on successful form submission.
Tap to save the properties.
Experience Manager Forms provides out-of-the-box success and error handlers for form submissions. Handlers are client-side functions that execute based on the server response. When a form is submitted, the data is transmitted to the server for validation, which returns a response to the client with information about the success or error event for the submission. The information is passed as parameters to the relevant handler to execute the function.
In addition, form authors and developers can write rules at form level to override default handlers. For more information, see Override default handlers using rules.
Let us first review the server response for success and error events.
The structure for the server response for submission success event is as follows:
{oneOf: [
{ properties : {
contentType : {"type" : "string", "enum" : ["xmlschema", "jsonschema"]},
data : {type : "string", description : "Form data in XML or JSON format"},
thankYouOption : {type : "string"}
}},
properties : {
contentType : {"type" : "string", "enum" : ["xmlschema", "jsonschema"]},
data : {type : "string", description : "Form data in XML or JSON format"},
thankYouContent: {type: "string"}
}
]
}
The server response in case of successful form submission includes:
The success handler reads the server response and accordingly redirects to the configured page URL or displays a message.
The structure for the server response for submission error event is as follows:
{
errorCausedBy : "<CAPTCHA_VALIDATION or SERVER_SIDE_VALIDATION>",
errors : [
{ "somExpression" : "<SOM Expression>",
"errorMessage" : "<Error Message>"
},
...
]
}
The server response in case of error in form submission includes:
The errors handler reads the server response and accordingly displays the error message on the form.
Form developers and authors can write rules, at form level, to override default handlers. The server response for success and error events is exposed at form level, which developers can access using $event.data
in rules.
Perform the following steps to write rules to handle success and error events.
Open the Adaptive Form in authoring mode, select any form object, and tap to open the rule editor.
Select Form in the Form Objects tree and tap Create.
Choose is submitted successfully or submission fails from the Select state drop-down list.
Define a Then action for the selected state. For example, select Navigate To and then type or paste a URL. You can also drag any function using the Functions tab to the rule.
Tap Done to save the rule.