联系表(Word preSS)不会提交 [英] Contact form (Wordpress) won't submit

查看:249
本文介绍了联系表(Word preSS)不会提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个主题字preSS,使用的的Akismet在表单和<一href="http://stackoverflow.com/questions/15300470/jquery-ajax-form-using-mail-php-script-sends-email-but-post-data-from-html-fo">jQuery AJAX 的脚本。我已经修改了所有相关领域的融入我的Word preSS的网站,即使使用的Akismet API密钥已经存在。这是我的code:

I am creating a theme in Wordpress, using an Akismet form and a jQuery AJAX script. I have modified all of the relevant areas to integrate into my Wordpress site, even using the Akismet API key that is already there. Here is my code:

表格

<form method="post" id="contact_form">
  <input id="name" type="text" name="name" tabindex="1"/> <label for="name">Name</label>
  <input id="email" type="text" name="email" tabindex="2"/> <label for="email">E-mail</label>
  <input id="website" type="text" name="website" tabindex="3" value="http://" /> <label for="website">Website</label>
  <textarea id="message" tabindex="4" rows="10" cols="60" name="message"></textarea>
  <input type="submit" value="Send E-mail" tabindex="5" />
</form>

的jQuery

<script>
$(function() {
    $("#contact_form").submit(function() {
        $.ajax({
            type: "POST",
            url: "<?php bloginfo('template_url'); ?>/inc/email.php",
            data: $(form).serialize(),
            success: function(){
                $('.success').fadeIn(1000);
            }
        });
        return false;
    });
});
</script>

PHP脚本

<?php
    require "Akismet.class.php";
    function send_mail( $name, $email, $website, $ip, $is_spam, $message) {
        $subject = '';
        if( $is_spam == true )
            $subject = "[SPAM?]"; 
        $subject .= "[Your_site.com] E-mail received from ".$author_name."//".$author_email."//".$ip;

        wp_mail( get_option('admin_email'), $subject, $message, $name.' <'.$email.'>');
    }
    if(isset($_POST['action'])) {
        $wp_key = get_option( 'wordpress_api_key' );
        $our_url = get_bloginfo( 'url' );

        $name = $_POST['name'];
        $email = $_POST['email'];
        $website = $_POST['website'];
        $message = $_POST['message'];
        $ip = $_SERVER['REMOTE_ADDR'];

        $akismet = new Akismet($our_url, $wp_key);
        $akismet->setCommentAuthor($name);
        $akismet->setCommentAuthorEmail($email);
        $akismet->setCommentAuthorURL($website);
        $akismet->setCommentContent($message);
        $akismet->setUserIP($ip);

        send_mail( $name, $email, $website, $ip, $akismet->isCommentSpam(), $message);
    }

当我提交表单,它处理的东西,我重定向到404页,即使URL相同的联系人页面。该电子邮件还没有发送。可能有人帮助我与那里的问题可能在于?

When I submit the form, it processes something and redirects me to a 404 page, even though the URL is the same as the contact page. The email also does not send. Could someone help me with where the issue may lie?

推荐答案

您形式将之前Ajax调用甚至会在一起来看看提交。使用 preventDefault 停止默认动作

Your form is going to submit before the ajax call even gets a look in. Use preventDefault to stop the default action

$(function() {
    $("#contact_form").submit(function(e) {
       e.preventDefault();
       ...

修改

我刚注意到你返回false,它的应该的实现同样的结果,但有时我发现它不

I just notice you return false, which should acheive the same result, but sometimes I have notice it does not

您可以尝试 preventDefault()

这篇关于联系表(Word preSS)不会提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆