Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Server side validation - query

harimst
Level 1
Level 1

I have a requirement to collect some info from casual visitor to the site (unauthenticated) using AEM Forms. On posting data to backend (custom rest endpoint), there may be some validation failures - in which case, the form should be rendered back to the user with the data filled in (whatever was just entered) along with an error message. The validation cannot be done from client side. I tried the 3 options below, none of them seem to work.

SlingHttpServletRequest wrappedErrorRequest = new CustomParameterRequest(slingRequest, "GET");

wrappedErrorRequest.setAttribute("error", "error details here");

wrappedErrorRequest.setAttribute("data", request.getParameter("jcr:data"));

//option 1

//slingRequest.getRequestDispatcher(slingRequest.getParameter(GuideConstants.SELF_URL) + ".html", options).forward(wrappedErrorRequest, response);

//option 2

GuideSubmitServlet.setForwardPath(slingRequest, slingRequest.getParameter(GuideConstants.SELF_URL)+ ".html", null,null );

//option 3

//GuideSubmitServlet.setRedirectUrl(slingRequest, slingRequest.getParameter(GuideConstants.SELF_URL + ".html");

In case of option 1 & 2, I get an error "resource cannot be modified". Turns out that I cannot forward to a page. With option 3, the request attributes are lost after the redirect. Any suggestions on how to resolve this?

Thanks

2 Replies
Mayank_Gandhi
Community Advisor
Community Advisor

Can you preserve the state of AF and try restoring it later. Check for getGuideState and restoreGuideState method in the GuideBridge API doc shared below :

Adaptive Forms Class: GuideBridge