简体   繁体   English

如何将表单提交操作从显示警报弹出窗口更改为重定向到新页面?

[英]How can I change a form submit action from displaying an alert popup to redirecting to a new page?

I'm trying to troubleshoot something someone else created (never a fun prospect) and want to eliminate an alert popup and have the user redirected to another page after form submission ... I've searched the web and found a couple of possible alternatives, but I also don't want to blow up the page, as I'm not all that experienced in PHP troubleshooting ... this is, I'm guessing, a painfully simple 101-level question, but many thanks in advance ... here's the relevant code: 我正尝试解决其他人创建的问题(从来没有一个有趣的前景),并希望消除警报弹出窗口,并在提交表单后让用户重定向到另一页...我已经在网上搜索了,发现了几种可能的替代方法,但我也不想炸掉页面,因为我对PHP故障排除的了解还不是全部...我想这是一个非常简单的101级问题,但要多谢。 ..这是相关代码:

    jQuery("form#commentform input#submit").click(function(event) {
        event.preventDefault();

        var name = jQuery("form#commentform input#author").val();
        if(name=="") {
            alert("Name cannot be empty!");
            jQuery("form#commentform input#author").focus();
            return false;   
        }

        var email = jQuery("form#commentform input#email").val();
        var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
        var email_test= pattern.test(email);  

        if (email == "" || email_test == false) {
            alert('Valid email address is required!');
            jQuery("form#commentform input#email").focus();
            return false;
        }

        var phone = jQuery("form#commentform input#url").val();
        var comment = jQuery("form#commentform textarea#comment").val();

        jQuery.get('http://theenergyclub.com/wp-content/themes/EnergyClub/formPost.php', {type:'guestpass', name:name, email:email, phone:phone, comment:comment, rnDnum:Math.random()}, function(data) {
            alert('We have received your request. Thank you!');

You can try to replace the last line 您可以尝试替换最后一行

alert('We have received your request. Thank you!');

with

window.location = "http://example.com/"

You should be able to just change alert('We have received your request. Thank you!'); 您应该能够更改alert('We have received your request. Thank you!'); to window.location = '<URL>'; window.location = '<URL>'; where <URL> is the URL you want to re-direct the user to. 其中<URL>是您要将用户重定向到的URL。

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

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