How to return a value from submit action and use it in the redirect page?

urs_h_

02-02-2016

Hi 

I wonder how I can make my custom submit action returning a value and have this value available on the redirect page saying as url parameter?

Example:

1) submit action generates a kind of ticket number

2) i want to use the ticket number previously generated by the submit action in a link on redirect page.

Regards,

Urs

Accepted Solutions (1)

Accepted Solutions (1)

urs_h_

09-02-2016

Hi Varun 

with the help of your answer and the answer from Mandeep (http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/aem-forms.topic.html/fo...) I could eventually pass a custom parameter to the redirect page 🙂

I'm using this dependency (in the bundle's pom.xml) to have the GuideSubmitServlet available in my custom submit action:

<dependency>     <groupId>com.adobe.aemfd</groupId> <artifactId>aemfd-client-sdk</artifactId> <version>6.1.0</version> <scope>provided</scope> </dependency>

and I'm using this code in the submit action to add a custom parameter to the url of the redirect page:

Map<String, String> redirectParameters = GuideSubmitServlet.getRedirectParameters(request); redirectParameters.put("answerToTheUltimateQuestion","42"); GuideSubmitServlet.setRedirectParameters(request,redirectParameters);

 

Thanks a lot four your help,

Urs

Answers (9)

Answers (9)

srikanthp689160

26-02-2018

Hi Urs,

Can you please let me know what is required to be redirected/forwarded to a page on form submission.

It works perfectly fine on adaptive form page but when i embed adaptive form on a sites page using OOTB AEM Form component (fd/af/components/aemform), submit button does not work, give me below exception

java.lang.IllegalArgumentException: Not a valid identifier 'index,index.html'.

Also, i would like to know how can we access custom parameter which was set in redirectParameters on thank you page.

I have configured target page in AEM Form component as well as in adaptive form page, Adaptive Form Container -> Submission section.

Thanks & Regards,

Srikanth Pogula.

Jared_Langdon

30-07-2018

Thanks Mayank.  I would like to use another form as my thank you page.  That seems to work, but I can't figure out how to pass data from my first form to the second one. 

Mayank_Gandhi

Employee

16-07-2018

Hi Jared,

You can create your own template[0] and then create a custom thank-you page based on your template.

[0] Creating Page Templates / Introducing Editable Templates - YouTube

Once you have your Page ready you can simply go the Adaptive form root container and set the redirect URL. Even if you do not have custom template or Page you can use the Sample templates provided for the testing purpose and create a page using we.retail or we. Gov (http://localhost:8080/lc/sites.html/content).

1529327_pastedImage_3.png

Jared_Langdon

16-07-2018

I have the same question.  I'm having trouble finding documentation that describes how to set up a custom thank you page.  Is there documentation or a blog post or a tutorial or an article on this anywhere?  Srikanth, did you find a solution?  Can you share it here?  Much appreciated if you can.  Thanks.

varundua

09-02-2016

Hi Urs,

From the documentation[1]

After performing the required action, the Submit servlet forwards the request to the forward path. An action uses the setForwardPath API to set the forward path in the Guide Submit servlet. 

If the action doesn't provide a forward path, the Submit servlet redirects the browser using the Redirect URL. The author configures the Redirect URL using the Thank You Page configuration in the Adaptive Form Edit dialog. You can also configure the Redirect URL through the Submit action or the setRedirectUrl API in the Guide Submit servlet. You can also configure the Request parameters sent to the Redirect URL using the setRedirectParameters API in the Guide Submit servlet.

We have a public API but seems like its missed in the documentation. To set the redirect url and parameters you can use the following APIs.

com.adobe.aemds.guide.servlet.GuideSubmitServlet public static void setRedirectUrl(final SlingHttpServletRequest req, final String redirectUrl) public static void setRedirectParameters(SlingHttpServletRequest request, Map<String, String> value)

[1]  https://helpx.adobe.com/aem-forms/6-1/custom-submit-action-form.html

Regards

Varun

urs_h_

08-02-2016

Hi arvmohan

I've already tried this by writing a custom URL to the reponse's location attribute in the header. 

response.setStatus(302); response.setHeader("Location", <custom redirect url>);

But setting the header in the custom submit action throws an IllegalStateException. Maybe the exception is thrown because the GuideSubmitServlet has already started to write to the response before my custom submit action is called.

Is there another possibility to set the redirect location?

Thank you,

Urs

arvmohan

08-02-2016

Hi Urs,

In your custom submit action, you yourself can redirect to Thank You page after your submission workflow is completed. You can get url for thank you page from ":redirect" parameter from the request.