Thanks for the response. I am unfamiliar with AEM in general.
After page submission, the user will be directed to another page, which must hold the newly-generated unique ID of the previous submission. At this point, further inputs from the user will be required.
I noticed that I could redirect using the "Redirect URL/Path" config in AEM Forms. However, it does not seem that I could retrieve the response from the server and pass it to the next page. Therefore, I used the code above to process the data, retrieve the response and redirect manually.
Appreciate if you could guide me on your alternative. Thanks.