Hello,
I want to perform two custom actions on a form submission. the form has two input fields, one for “seed code” and another for “email”.
There are 6 possible seed codes, and I want to collect the email into Mailchimp.
On submit, the following two things should happen:
- Validate email and submit to Mailchimp.
- Validate seed code (01, 02, 03, 04, 05, 06) and use that value to redirect to appropriate page e.g. /seed-02, /seed-03, /seed-04 etc.
I have been browsing the forums but haven’t been able to piece together a working solution.
My code at the moment:
<script>
(function clickMe() {
const seed_submit_button = document.getElementById("seed-submit-button");
seed_submit_button.addEventListener('click', submit);
function submit() {
seed_code_text = document.getElementById("seed-code-text").value;
console.log(seed_code_text);
window.location.replace(window.location.href + "seed-" + seed_code_text);
}
})();
</script>
My major problem seems to be that the onClick event happens before the form submission in which case the user is redirected to the appropriate page but the email address is not sent to Mailchimp. Is there a way in JS to explicitly trigger the form POST event before I redirect the user?
I tried something like document.getElementById("email-form").submit();
but no luck there.
Thank you!
live site:
https://seed-prototype.webflow.io/
Here is my site Read-Only: https://preview.webflow.com/preview/seed-prototype?utm_medium=preview_link&utm_source=designer&utm_content=seed-prototype&preview=a7600e740261acd42d518118e8edadf5&workflow=preview