In the folder create either:
- A post script.
The name of the script is post.POST.<extension>; e.g. post.POST.jsp
The post script is invoked when a form is submitted to process the form, it contains the code that handles the data arriving from the form POST.
- Add a forward script which is invoked when the form is submitted.
The name of the script is forward.<extension>; e.g. forward.jsp
This script can define a path. The current request is then forwarded to the specified path.
The necessary call is FormsHelper#setForwardPath (2 variants). A typical case is to perform some validation, or logic, to find the target path and then forward to that path, letting the default Sling POST servlet do the actual storage in JCR.
There could also be another servlet that does the actual processing, in such a case the form action and the forward.jsp would only act as the "glue" code. An example of this is the mail action at /libs/foundation/components/form/actions/mail, which forwards details to <currentpath>.mail.html where a mail servlet sits.
- a post.POST.jsp is useful for small operations that are fully done by the action itself
- while the forward.jsp is useful when only delegation is required.
The order of execution for the scripts is:
- Upon rendering the form (GET):
- for all field's constraints: clientvalidation.jsp
- form's validationRT: clientvalidation.jsp
- form is loaded via load resource if set
- addfields.jsp while inside rendering <form></form>
- upon handling a form POST:
- for all field's constraints: servervalidation.jsp
- form's validationRT: servervalidation.jsp
- if a forward path was set (FormsHelper.setForwardPath), forward the request; then call cleanup.jsp
- if no forward path was set, call post.POST.jsp (ends here, no cleanup.jsp called)