We are using a third-party vendor (formstacks) for building forms in our website. We need to implement a gated content with the formstacks form. Basically, certain pages shouldn't be accessible without submitting the form. We have implemented these using cookies when the page is accessed we will check if there is a cookie present if not we will redirect to the form page.
The issue we are facing is that we need a way to set a cookie on the form submit. But since we are using a third-party vendor for the form we don't have any access to modify how the form is submitted. They do the form submit by doing a POST request to a URL and will redirect to our desired page after submit is successful (redirect is configured in formstacks).
We tried using beforeunload event to set the cookie which will set the cookie right before the redirect after the form is submitted but the issue is we find this not too reliable in all the browsers.
Is there any way to listen for the POST request being sent to set the cookie (note the POST request is not an xhr request) Note: the form submission has to be successful before submitting the cookie so doing in form submit event is not an option because there are validations in place
Any suggestions are welcome (we know building a custom form is the easier solution but it's not an option for us).