我试图检查登录表单中是否存在用户名和密码字段。
问题是if (!empty ($_POST))
代码不会对我这样做。
UPDATE:
if (isset($_POST[\'submit-btn\'])) {
//Sanitize POST Array
$POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
$username = $POST[\'username\'];
$password = $POST[\'password\'];
if(empty($username)) {
echo "Username o email non inserita";
return false;
}
if(empty($password)) {
echo "Password non inserita";
return false;
}
if($username && $password) {
$login_array = array();
$login_array[\'user_login\'] = $username;
$login_array[\'user_password\'] = $password;
$verify_user = wp_signon($login_array, true);
if (!is_wp_error($verify_user)) {
echo "<script>window.location = \'" . site_url() . "\'</script>";
} else {
echo \'Credenziali non valide!\';
}
}
}
相反,这是同一页面上的登录表单,即“我的登录”。php页面:
<form id="wp_login_form" action="/login/" method="post">
<label class="my-username" >Username o Email</label>
<input type="text" name="username" class="info-login" value="" placeholder="[email protected]">
<label class="my-password" >Password</label>
<input type="password" name="password" class="info-login" value="" placeholder="******">
<label>
<input class="myremember" name="rememberme" type="checkbox" value="forever"><span class="hey">Remember me</span>
</label>
<button type="submit" id="submitbtn" name="submit-btn" value="Login">Login</button>
</form>
非常感谢那些帮助我的人。顺致敬意,