DocumentationAEMAEM TutorialsAEM Forms Tutorials

PrePopulate Adaptive Forms using query parameters

Last update: March 23, 2025
  • Applies to:
  • Experience Manager 6.5
  • Topics:
  • Adaptive Forms

CREATED FOR:

  • Experienced
  • Developer

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);
NOTE
If your form is using schema the structure of your xml will be different and you will have to build the xml accordingly.

Deploy the assets on your system

  • Download and install the Adaptive Form Template using the Package Manager

  • Download and install the sample adaptive form

  • Preview the adaptive form
    You should see the adaptive form populated with the value John and Doe

recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e