Wordpress模板导致404错误


Wordpress Template causes 404 Error

我在Wordpress中创建了一个页面,并将此表单用作模板。但当我提交表格时,它显示Error 404 page not found

我尝试过php中的各种脚本,但没有取得丰硕的成果。希望得到最好的答案。谢谢:)

这是我的编码

<?php
/*
template name: visit
*/
$servername= "localhost";
$username="root";
$password="";
$database="wp_chandan"; 

if(isset($_POST['name']) && isset($_POST['email']))
{
    $name=$_POST['name'];
    $email=$_POST['email'];
    var_dump($email);

    @mysql_connect($servername,$username,$password);
    @mysql_select_db($database);
    $query=mysql_query("insert into visitor_d (NAME,Email) values ('$name','$email') ");    
} ?>
<html>
    <head>  
        <?php get_header(); ?>
        <style type='text/css'>
        /* form elements */
        form {
            margin:100px; 
            padding: 10px 2px;
            background: #F5F5F5;  
            width: 50%;
            height:auto;
            border:1px solid green;
        }
        input {
            padding:2px;
            border:1px solid #eee;
            font: normal 1em Verdana, sans-serif;
            color:#777;
            align:center;
        }
        input.button { 
            font: bold 12px Arial, Sans-serif; 
            height: 24px;
            margin: 0;
            align:center;
            padding: 2px 3px; 
            color: #333;
            background: #e7e6e6 url(MarketPlace-images/button.jpg) repeat-x;
            border: 1px solid #dadada;
        }
        </style>
    </head>
    <form action="" method="POST">
        <fieldset>
            <legend><b><u>Visitor Details:</u></b></legend>
            Name: <input type="text" name="name" placeholder="Fill Name" required><br><br>
            Email: <input type="text" name="email" required placeholder="Enter Email"><br><br>
            <input type="submit" name="submit"><br>
        </fieldset>
    </form>
    <?php get_footer();?>
</html>

确保表单字段中的name属性中没有任何保留的WordPress术语。

WordPress在内部重写时使用了许多保留术语,因此,如果您使用name属性(如"名称"),它会破坏WordPress重写规则,并在提交表单后导致此404未找到页面。

点击此处查看更多信息:http://www.lost-in-code.com/platforms/wordpress/wordpress-404-not-found-when-submitting-form/

html5不喜欢空的action属性,它确实会在一些浏览器中引起问题。你还没有选择一个标准,所以我认为浏览器将默认为html5

<form action="#" method="POST"> 

将操作设置为#应该有效,但需要注意的是,在加载页面模板之前添加的操作,这显然会占用$_POST,重定向也很常见,这可能也是原因之一。

还有

Name: <input type="text" name="name" placeholder="Fill Name" required>

WP不喜欢当你称一个字段为"名称"时,它与某些内容冲突(我现在已经忘记了原因)

 Name: <input type="text" name="aname" placeholder="Fill Name" required>