We have just started using Netlify Forms with a Netlify Function back end (our submission-created.js handler) on our site and are pleased with how everything is working for the most part. But I do have a question about what our options are conditionally redirecting the user in browser post-form submission.
I understand the standard way is to set the action of the form to the page you want to redirect to post-submission. And we have another form on the site where we preventDefault the submission and then, based on the values in one of the form fields, manually redirect them to different post-submission pages in the client side js.
But we have one form where we would like to submit the form, and then check an external DB in the submission-created handler, and then depending on that retrieved data, we would like to redirect the user in browser to different pages. We cannot do this client side like described above because in this case it’s not dependent on the values of the form fields, but instead, the api call we make in the function back end.
Which brings me to my question: is it possible to send a response back to the browser from the back end lambda to route the user post-submission instead of just relying on the static form action or client side manual redirects? Would like to be able to respond to the form submission with something like:
const response = {
statusCode: 301,
headers: {
Location: location
}
}
return response
And have the user routed to that location in browser upon success, but have not had any success thus far with this approach. Is this possible? Is this documented somewhere in the docs that I might have missed? Thank you for any assistance in advance!