所以我得到了主机,在它上面安装了wordpress,我把我的html放在它上面,它包含用html编写的联系表单,它有单独的php文件和进程。来到网站时访问的主文件是" front-page.php"获取元素并且它有效,但在我提交表单后,我将我重定向到www.mywebsite.com/front-page.php而不是www.mywebsite.com,我在第2行中得到错误,之前有效,它是行& #34; ,我该怎么办,如何解决这个问题?添加代码
<?php
// define variables and set to empty values
$name_error = $email_error = $message_error = "";
$name = $email = $phone = $message = $url = $success = "";
//form is submitted with POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$name_error = "Name is required";
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$name_error = "Only letters and white space allowed";
}
}
if (empty($_POST["email"])) {
$email_error = "Email is required";
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$email_error = "Invalid email format";
}
}
if (empty($_POST["message"])) {
$message_error = "Message is required";
} else {
$message = test_input($_POST["message"]);
}
if ($name_error == '' and $email_error == '' and $message_error == '' and $url_error == '' ){
$message_body = '';
unset($_POST['submit']);
foreach ($_POST as $key => $value){
$message_body .= "$key: $value\n";
}
$to = 'ignas.levinskas@mail.com';
$subject = 'Contact Form Submit';
if (mail($to, $subject, $message)){
echo("<script> window.location.href='../front-page.php'</script>");
$name = $email = $message = '';
}
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
&#13;
<form id="contactform" method="post" action="http://li-designs.com/wp-content/themes/vcs-starter/assets/app.php" >
<input name="name" type="text" class="feedback-input" placeholder="Name" required/>
<span class="error"><?= $name_error ?></span>
<input name="email" type="text" class="feedback-input" placeholder="Email" required/>
<span class="error"><?= $email_error ?></span>
<textarea name="message" type="text" value="<?= $message ?>" class="feedback-input" placeholder="Message" ></textarea>
<span class="error"><?= $message_error ?></span>
<button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Send</button>
</form>
&#13;
答案 0 :(得分:0)
您是否尝试在post方法中使用标题?
header('location': 'www.mywebsite.com');
在普通的PHP中,它会将您重定向到该URL。