wordpress主题中ajax联系人表单的问题


Issues with ajax contact form inside wordpress theme

我在一个网站上遇到了一个问题。此页中的表单:

http://www.emerygrid.ru/en/service/product-samples/

似乎根本不起作用…表单甚至没有验证,更不用说发送电子邮件了!

应该先验证(有错误处理),然后发送电子邮件(在WP选项中设置)

我没有太多的细节信息,但如果有人愿意指出我在正确的方向,我很乐意提供信息。请记住,我不是很擅长Jquery,所以你必须让它对我来说非常简单....

感谢的人!

当你点击提交时什么都不会发生因为在你的js中你调用了这个

$(".comment_form, .contact_form").submit(function(event),并且您已经使用了event.preventDefault();,因此表单不显示默认行为。检查控制台是否有一个错误在你的js。上面写着

TypeError: $(…)。Block不是函数

你需要先修复这些错误。

这是处理表单的js。

 if($(".contact_form").length)
            $(".contact_form")[0].reset();
        if($(".comment_form").length)
            $(".comment_form")[0].reset();
        $(".comment_form, .contact_form").submit(function(event){
            event.preventDefault();
            var data = $(this).serializeArray();
            var id = $(this).attr("id");
            $("#"+id+" .block").block({
                message: false,
                overlayCSS: {
                    opacity:'0.3',
                    "backgroundColor": "#FFF"
                }
            });
            $.ajax({
                url: config.ajaxurl,
                data: data,
                type: "post",
                dataType: "json",
                success: function(json){
                    //$("#"+id+" [name='submit'], #"+id+" [name='name'], #"+id+" [name='contact_name'], #"+id+" [name='telephone'], #"+id+" [name='email'], #"+id+" [name='products']").qtip('destroy');
                    if(typeof(json.isOk)!="undefined" && json.isOk)
                    {
                        if(typeof(json.submit_message)!="undefined" && json.submit_message!="")
                        {
                            $("#"+id+" [name='submit']").qtip(
                            {
                                style: {
                                    classes: 'ui-tooltip-success'
                                },
                                content: { 
                                    text: json.submit_message 
                                },
                                position: { 
                                    my: "right center",
                                    at: "left center" 
                                }
                            }).qtip('show');
                            //close tooltip after 5 sec
                            /*setTimeout(function(){
                                $("#"+id+" [name='submit']").qtip("api").hide();
                            }, 5000);*/
                            if(id=="comment_form" && typeof(json.html)!="undefined")
                            {
                                $(".comments").html(json.html);
                                $("#comment_form [name='comment_parent_id']").val(0);
                                if(typeof(json.comment_id)!="undefined")
                                {
                                    var offset = $("#comment-" + json.comment_id).offset();
                                    $("html, body").animate({scrollTop: offset.top-10}, 400);
                                    if(typeof(json.change_url)!="undefined" && $.param.fragment()!=json.change_url.replace("#", ""))
                                        $("#comment_form [name='prevent_scroll']").val(1);
                                }
                                if(typeof(json.change_url)!="undefined" && $.param.fragment()!=json.change_url.replace("#", ""))
                                    $.bbq.pushState(json.change_url);
                                    //window.location.href = json.change_url;
                            }
                            $("#"+id)[0].reset();
                            $("#cancel_comment").css("display", "none");
                            $(".contact_form [name='department']").val("");
                            $(".contact_form .tabs_box_navigation_selected>span").text("Select department");
                        }
                    }