Pre-populate form fields
Hi,
I have an adaptive form which has unbound and bound fields because it it partially based on a XDP form model.
I now need to pre-fill some of the fields with data from the currently logged in user.
I found Adobe example files and took the following route:
- Created a prefill.jsp
- Include the prefill.jsp in the head.jsp of the form
- prefill.jsp gets the user data and creates the xml:
<%
final boolean isAnonymous = UserPropertiesUtil.isAnonymous(slingRequest);
boolean isDisabled = WCMMode.fromRequest(request).equals(WCMMode.DISABLED);
if(!isAnonymous && isDisabled && slingRequest.getParameter("dataRef")== null
&& slingRequest.getAttribute("data")==null){
UserProperties userProperties = slingRequest.adaptTo(UserProperties.class);
String givenName = userProperties.getProperty("givenName");
String dataXML="<afData>" +
"<afBoundData>" +
"<dataRoot>" +
"<General_firstName>"+ StringUtils.trimToEmpty(userProperties.getProperty("givenName")) + "<General_firstName>" +
"</dataRoot>" +
"</afBoundData>" +
"</afData>";
slingRequest.setAttribute("data", dataXML);
}
%>
In the above snippet, "<General_firstName>" is the element name of the form field.
The jsp is included and has no errors, but the field is not pre-filled. Does the XML need a different structure? The above field was dragged from the content finder (the loaded XDP) but I also have unbound fields.
Any help is greatly appreciated.
Please don't point me to the documentation - https://helpx.adobe.com/aem-forms/6-1/prepopulate-adaptive-form-fields.html - since it did not help me :(
Thanks, Alex
