This is my code in insert PHP plugin. I have added this PHP snippet generated by the plugin in a page in WordPress. The wp_redirect
is not working with this snippet.
// define variables and set to empty values
$emailErr = $passwordErr = "";
$email = $password = "";
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["email"])) {
$emailErr = "Email is required";
}
else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}
if (empty($_POST["password"])) {
$passwordErr = "Password is required";
} else {
$password = test_input($_POST["password"]);
// check if URL address syntax is valid (this regular expression also allows dashes in the URL)
//if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$website)) {
// $websiteErr = "Invalid URL";
//}
if ($emailErr == "" && $passwordErr == "")
{
wp_redirect("https://grenstonhrs.000webhostapp.com",301);
exit;
}
}
}
?>
<div>
<form id="form" method="POST">
Email
<br/>
<input name="email" style="width: 300px;" type="text" value="<?php echo $email;?>" />
<span style="color: #FF0000"><?php echo $emailErr;?></span>
<br/>
Password
<br/>
<input name="password" style="width: 300px;" type="password" />
<span style="color: #FF0000"><?php echo $passwordErr;?></span>
<br/>
<br/>
<input id="loginButton" name="loginButton" type="submit" />
</form>
<br/>
<a href="https://grenstonhrs.000webhostapp.com/sign-up/">Sign Up</a>
</div>