Passing values from one form to another



I need to present a Form B to the user after he submits Form A.  Form B needs to be prefilled with data based on values entered by the user in Form A.  I know how to set up a custom submit service.  I know how to specify Form B as the redirect for Form A so that it appears after a successful submit.  I also know how to set up a custom prefill for Form B.  What I can't seem to do is pass anything from Form A's submit service to the prefill service for Form B.  I must be missing something obvious, but I've searched high and low with no success.

In the prefill service I have access to DataXMLOptions.  From there I can get a user ID, but that's not useful because these may be anonymous users.  Is there anything that I can set in my submit service that I can access through DataXMLOptions (e.g. a session ID)?  If so, I could stage what I need in a file or a database during the submit service and retrieve it again in the prefill service.  I just don't see any way of doing that.

Any help is greatly appreciated.  Thanks.

View Entire Topic



You will need to create a custom submit action for your form. In your post.POST.jsp you'll need to get the data from your form and then handle the redirect. There are numerous ways to do this but here are a few sample lines:

Get the XML from the submitted form:

String formXML = request.getParameter("jcr:data");

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder;

builder = factory.newDocumentBuilder();

org.w3c.dom.Document doc = builder.parse( new InputSource( new StringReader( formXML ) ) );

Extract some specific data:

XPath xPath = XPathFactory.newInstance().newXPath();

String someID = xPath.compile("//SomeID").evaluate(doc);

Prepare and do some redirection (other code included that I thought would be useful that I had to dig around for too):

final String nodePath = properties.get("nodePath", null);

final StringBuilder path = new StringBuilder(request.getContextPath());

final String programCoursesURL = "/content/some-project/someForm.html?RecordID=" + someID;



In this case the form had a template that read the recordID parameter and pre-filled from a DB using the RecordID. You can also use a "dataRef" service too. The redirect code was a tough piece to get over though.