PrePopulate Adaptive Forms using query parameters
One of our customers had the requirement to populate adaptive form using the query parameters. For example in the following url the FirstName and LastName fields in the adaptive form are set to John and Doe respectively
https://forms.enablementadobe.com/content/forms/af/testingxml.html?FirstName=John&LastName=Doe
To accomplish this use case a new adaptive form template was created and associated with a page component. In this page component we have a jsp to get hold of the query parameters and create an xml structure that can be used to populate the adaptive form.
The details on creating a new Adaptive Form template and page component are explained in this video.
The following is the code that was used in the jsp page
java.util.Enumeration enumeration = request.getParameterNames();
String dataXml = "<afData><afUnboundData><data>";
while (enumeration.hasMoreElements())
{
String parameterName = (String) enumeration.nextElement();
dataXml = dataXml + "<" + parameterName + ">" + request.getParameter(parameterName) + "</" + parameterName + ">";
}
dataXml = dataXml + "</data></afUnboundData></afData>";
//System.out.println("The data xml is "+dataXml);
slingRequest.setAttribute("data", dataXml);
Deploy the assets on your system
-
Download and install the Adaptive Form Template using the Package Manager
-
Preview the adaptive form
You should see the adaptive form populated with the value John and Doe