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