我已经使用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()
。