I’m trying to check if the username and password fields are present in the login form.
The problem is that the if (!empty ($_POST))
code does not do this to me.
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!';
}
}
}
This is instead the login form that is on the same page, that is on the my-login.php page:
<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="example@gmail.com">
<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>
Thanks a lot to those who will help me. Best regards.