繁体   English   中英

Wordpress 联系表同页

[英]Wordpress Contact Form Same Page

我在 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();
?>

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

添加 input name="name" 和 input name="e-mail" 的相同问题。 通过将 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">

暂无
暂无

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

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