繁体   English   中英

在 wordpress 中创建自定义表单

[英]Creating custom forms in wordpress

我使用 POST 方法在 wordpress 中创建了一个自定义表单。 但是,在提交时,我收到“页面不存在错误”...我在表单操作中使用的主题目录中添加了一个自定义页面“custompage1.php”。 如果您可以查看代码,那就太好了。

<html>
<head>
    <title>Meal Planner</title>
</head>
<body>
    <?php function checkregion($Region) 
    { 
   SWITCH ($Region) 
   { case "North": 
    echo "test1"; 
  break; 
 case "South": 
 echo "test2"; 
 break; 
 case "East": 
 header( 'location:https://www.test3.com/'); 
 break; 
 case "West": 
header( 'location: https://www.test4.com/'); 
break; 
} } 
 checkregion($Region); ?>
    <form action="../custompage1.php " method="POST">
        <method="POST">
            <p>Name</p>
            <input type="text" name="name">
            <p>Email</p>
            <input type="text" name="email">
            <p>Phone</p>
            <input type="text" name="phone">
            <p>Dropdown Box</p>
            <select name="Region" size="1">
                <option value="North">North</option>
                <option value="South">South</option>
                <option value="East">East</option>
                <option value="West">West</option>
            </select>
            <br />
            <input type="submit" value="SUBMIT">
            <input type="reset" value="CLEAR">
    </form>
</body>
</html>

您可以使用get_template_directory_uri()获取可通过浏览器访问的主题目录的路径。 https://developer.wordpress.org/reference/functions/get_template_directory_uri/

<form action="<?= get_template_directory_uri() ?>/custompage1.php" method="post">
    ...
</form>

不过,值得指出的是,如果您使用的是子主题,则应改用get_stylesheet_directory_uri()

暂无
暂无

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

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