How to not redirect people on submit (Mailchimp Custom Form)?

  • Thread starter Federico Visioli
  • Start date
F

Federico Visioli

Guest
I made a custom form with mailchimp, with custom css and custom JavaScript for errors. But, when you click on submit, the form redirects you to a thank you page or to a error page, and I don't like that. In my JavaScript code, I already have the error' messages set onclick.

This is my html (I only put the input codes):

<form action="----/subscribe/post-?u=----;id=----" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>

<input type="text" value="" name="FNAME" class="required form-input" placeholder="Nome..." id="mce-FNAME">
<div id="obbligo-nome" class="obbligo" style="color:red">Required</div>

<input type="email" value="" name="EMAIL" class="required email form-input" placeholder="Email..." id="mce-EMAIL">
<div id="obbligo-email" class="obbligo" style="color:red">Required</div>

<input type="radio" value="Acconsento al trattamento dei miei dati personali." name="CONSENSO" id="mce-CONSENSO-0">
<div id="obbligo-consenso" class="obbligo" style="color:red">Required</div>

<input type="submit" value="ACCEDI" name="subscribe" id="mc-embedded-subscribe" class="button">


So, I set my vars and my onclick, and everything works fine.

var username=document.getElementById("mce-FNAME");
var email=document.getElementById("mce-EMAIL");
var consenso=document.getElementById("mce-CONSENSO-0");
var login=document.getElementById("mc-embedded-subscribe");

login.onclick=function() {
if (username.value.length==0){
document.getElementById("obbligo-nome").style.display = "block";
}

if (email.value.length==0){
document.getElementById("obbligo-email").style.display = "block";
}

if (consenso.checked==false){
document.getElementById("obbligo-consenso").style.display = "block";
}
}


The only problem is that it redirects by submitting to a mailchimp's thank you page or to the errors page (I don't want this, I'd like to show everything on my website page into the form).

I know that this redirect is caused by the "form action" in the html, but how can I block this? Thank you so much.

PS: I saw other questions about this, but I didn't understand so much, I'm new to javascript and I don't know jQuery.

Continue reading...
 
Top