Wordpress联系表单同一页面

时间:2014-02-04 21:44:14

标签: php html wordpress

我在一个标题为“联系人”的页面上有Wordpress的联系表单。我正在尝试将其提交到同一页面,因为我在自定义页面模板中的同一页面上有php邮件代码。在提交时,URL仍然作为wordpress / contact /加载,但wordpress内容只显示为Not Found,就像没有联系页面一样。如果我将动作设置为Wordpress外的mail.php,它可以正常工作。我完全陷入了困境。

<form class="alignleft" id="contact" action="[insert_php] the_permalink(); [/insert_php]" method="post">
    <input id="name" type="text" name="name" placeholder="Name" required="" />
    <input id="email" type="email" name="email" placeholder="Email" required="" />
    <select id="subject" name="subject">
        <option value="General Question">General Question</option>
        <option value="General Donation Information">General Donation Information</option>
        <option value="Membership Information">Membership Information</option>
        <option value="Taste of Loveland - Restaurant Vendor Information">Taste of Loveland - Restaurant Vendor Information</option>
        <option value="Taste of Loveland - Silent Auction Information">Taste of Loveland - Silent Auction Information</option>
        <option value="Tree for All - Tree Donation Information">Tree for All - Tree Donation Information</option>
        <option value="Tree for All - Fashion Show Information">Tree for All - Fashion Show Information</option>
        <option value="Other Event Information">Other Event Information</option></select>
    <textarea id="message" cols="40" maxlength="800" name="message" placeholder="Message" required="" rows="6"></textarea>
    <input type="submit" name="submitted" value="Send" />
</form>

这是用于页面的page-contact.php自定义页面模板。

<?php
get_header(); ?>

<div id="main-content" class="main-content">

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

<?php
if(isset($_POST['submitted'])) {
        $mailTo = "test@wboco.com";
        $subject = $_POST['subject'];
        $message = $_POST['message'];
        $email = $_POST['email'];
        $name = $_POST['name'];
        $body = "New message from FHSL contact form:<br><br>".$message."<br>";   
        $headers = "To: <".$mailTo.">\r\n";
        $headers .= "From: ".$name." <".$email.">\r\n";
        $headers .= "Content-Type: text/html";
        $mail_success =  mail($mailTo, utf8_decode($subject), utf8_decode($body), $headers);    
}
?>


            <?php
                // Start the Loop.
                while ( have_posts() ) : the_post();

                    // Include the page content template.
                    get_template_part( 'content', 'page' );

                endwhile;
            ?>

        </div><!-- #content -->
    </div><!-- #primary -->
</div><!-- #main-content -->

<?php
get_footer();
?>

2 个答案:

答案 0 :(得分:4)

为所有表单输入名称添加前缀(例如cf_name而不是name),我遇到了这个问题,由于某些原因,WordPress会使用其中一些名称值,如果被覆盖则会抛出404。我不清楚为什么,但我很肯定这是你的问题!

答案 1 :(得分:0)

使用输入名称=“名称”和输入名称=“电子邮件”添加相同的问题。通过在输入名称中添加prefix_来解决。

<input type="text" name="prefix_name" id="name" class="" placeholder="prefix_name">
<input type="email" name="prefix_email" id="email" class="" placeholder="prefix_email">