Hello All,
I’m trying to create a form where the Submit button automatically triggers a file download. I have a direct download link from Google Drive, and I know about putting that URL into the redirect URL field in the form. Doing that does trigger the download, but it seems to break the default success and error messages. The button gets stuck on the Please Wait… text, and there is no confirmation that the form has gone through. Is there a way to trigger the file download but keep the default success and error messages?
If this doesn’t work I can just put a download button in the success screen, but would like to keep it to one click if at all possible.
Thanks!
Here is my site Read-Only: Form Test
(how to share your site Read-Only link)
I was also having the same problem, but I was able to solve it with this code, you just need to replace the download link where it says ‘[DOWNLOAD LINK]’:
<script>
document.addEventListener("DOMContentLoaded", function() {
var form = document.querySelector('form'); // Select your form
form.addEventListener('submit', function(event) {
event.preventDefault(); // Prevent default form submission
// First Function: Redirect to the Google Drive download link
window.location.href = "[DOWNLOAD LINK]";
// Second Function: Simulate a delay to allow the redirect to process
setTimeout(function() {
// Trigger the Webflow success message manually
var successMessage = document.querySelector('.w-form-done');
var errorMessage = document.querySelector('.w-form-fail');
if (successMessage) {
successMessage.style.display = 'block';
}
if (errorMessage) {
errorMessage.style.display = 'none';
}
// Hide the form after showing the success message
form.style.display = 'none';
}, 1000); // Adjust the delay as needed
});
});
</script>