简体   繁体   English

验证后表单未提交数据

[英]Form not submitting data after validation

long time reader first time poster.长期读者第一次海报。 I am having an issue with a form.我的表格有问题。 It has email validator with JavaScript and once the validation is correct it supposedly has to submit the data but this doesn't happen.它有 email 验证器和 JavaScript,一旦验证正确,它应该提交数据,但这不会发生。 If I run the form without the validation the data goes through without a problem but with the validation I have a success message and then no data.如果我在没有验证的情况下运行表单,则数据会毫无问题地通过,但通过验证,我会收到一条成功消息,然后没有数据。

function ValidateEmail(email)
{
    var mailformat = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
    if(!email.match(mailformat))
    {
        alert("valid email is required");
        return false;
    }else{
        document.querySelector('form').submit();
        setTimeout(function(){
            window.parent.location = "https://www.xxxs.com/";           
        }, 3000);
    }
    
}

window.onload= function(){
 document.querySelector('input[type="submit"]').addEventListener("click", 
    function(e){
        e.preventDefault();
        var email = document.querySelector('input[name^="Email"]').value;
        ValidateEmail(email);
    }); 
}

Thank you for your help谢谢您的帮助

You haven't provided the markup to go along with it, so I can only speculate that there's a problem with the markup.您还没有提供 go 的标记,所以我只能推测标记有问题。

I also have no idea why you've added this.我也不知道你为什么添加这个。

setTimeout(function(){
    window.parent.location = "https://www.xxxs.com/";           
}, 3000);

Apart from this, it works pretty well for my sandbox .除此之外,它对我的 sandbox非常有效。

PS: I can't comment yet due to reputation, but @Kayden van Rijn might be interested in PS:由于声誉,我还不能发表评论,但@Kayden van Rijn 可能有兴趣

/* Links that start with "https" and end in ".org" */
a[href^="https"][href$=".org"] {
  color: green;
}

from MDN Web Docs来自MDN Web 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM