0
我有一个自定义的PHP窗体提交给API。我想将此表单添加到我的Wordpress网站的侧边栏中。当我尝试自定义form.php页面时,它工作正常,提交给API并重定向。WordPress的自定义窗体将不会重定向
当我将custom-form.php包含到我的sidebar.php中时,它不想重定向,但它仍然提交给API。
我知道标题需要在其他任何加载之前发生,但是如果我将它包含到页面中,我怎么才能加载它?
header('Location: http://example.com');
有没有更好的方法来将我的表单添加到WordPress的侧边栏?
代码看起来是这样的:
<?php
if (isset($_REQUEST['submitted'])) {
$errors = array();
if (!empty($_REQUEST['name'])) {
$name= $_REQUEST['name'];
}
else {$errors[] = 'You forgot to enter your name';}
}
if (isset($_REQUEST['submitted'])) {
if (empty($errors)) {
include 'myapi.php';
header('Location: http://example.com');
}
}
//Rest of code....
//Output validation errors
//HTML Form