Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Check for $ _POST fields in a POST method form

if you want to check username and password fields, try below code

if (isset($_POST['submit-btn'])) {
    $username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);
    $password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);
    if(empty($username))
    {
        echo "Username empty"; return false;
    }
    if(empty($password))
    {
        echo "Password empty"; 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!';
        }
    }
}

let me know if this works for you!

Related Posts:

  1. Change default login auth
  2. How can I redirect user after entering wrong password?
  3. Custom login form
  4. Prevent wp_login_form() from redirecting to wp-admin when there are errors
  5. How do I change the language of only the login page?
  6. Disable WordPress 3.6 idle logout / login modal window / session expiration
  7. Avoid to load default WP styles in login screen
  8. How to fake a WordPress login?
  9. Can not login with correct username and password
  10. How can I add a custom script to footer of login page?
  11. How to keep always logged in development environment
  12. I want to disable E-Mail verifcation / activation when a user signs up for my WordPress site
  13. custom login page redirect to logged in user profile page
  14. Action wp_login_failed not working if only one field is filled out
  15. How to customise wp-login.php only for users who are setting a password for the first time?
  16. Gaining Login Access via the Database
  17. WordPress Login Footer URL
  18. Remove built in wordpress login and use only google auth
  19. Change Login Page for a Multisite Subsite
  20. Positioning the “Lost your password?” and “← Back to Site”
  21. send users logging in from wp-login.php directly to home page of site, rather than dashboard
  22. How to get login data (session) outside WordPress?
  23. Add class to input form in login form
  24. Allow access to a page for admins only
  25. Customizing login error messages
  26. Customizing the WordPress login form
  27. Restricting frontend acess based on user role otherwise redirect to login form
  28. how to restrict user login whenever if a user puts on hold by editing wp-login action?
  29. How do I force “users must be registered and logged in” on subsites?
  30. deny IPs from wp-login using .htaccess
  31. Passing username to login screen
  32. Login error redirecting to wp-login page
  33. How can I prevent my custom form from redirecting to wp-login?
  34. reset password link redirect to login page
  35. How do I replace “Username” in the WordPress login form?
  36. Custom Login iframe doesn’t work
  37. Password reset – Disabled for LDAP accounts
  38. How to Get Logged-in to “Remote WP Site” from my local script (in Same Browser)?
  39. Replace dash with space in username on login
  40. Autologin only working the second time
  41. replace wp-login.php login forms via a hook & use custom forms with wp-login form validation
  42. Auto login between word press subdomain and a .net website
  43. Disabling standard registration login with username/email and password?
  44. How to change wordpress Log In text
  45. WordPress error on log out ‘Not Permitted’ and can’t log out
  46. Redirect wp-login
  47. Is wp_login_form secure on a non secure page?
  48. Is the login encrypted before it is sent? If so how to do I encrypt it the same way?
  49. Form Action submit over https
  50. Is there anyway to get the inputted password string from the login form?
  51. Login and Forgot password in Lightbox
  52. Forcing frontend login with UI switch
  53. Prevent display password on wp-login.php
  54. wordpress login without password just email address (NO 2 factor authentication with email)
  55. WordPress SSL not working [closed]
  56. Where is the php file, that does the checks for login information?
  57. Cannot Get User id after login success in file wp_login.php
  58. Alert Message through email or phone(Message)
  59. Moving from one host to another – cannot access the dashboard
  60. Temporally disable password to login with empty password?
  61. How are all users now set to inactive?
  62. woocommerce store login not working at first time
  63. How do I change the language of the login page to Arabic?
  64. How do you implement a login feature on a WordPress site?
  65. How to add custom authentication to wordpress login and register
  66. Problem in auto login after registration
  67. Login form does not store/remember/suggest users password
  68. Custom user roles are unable to login
  69. Using is_user_logged_in() to lock down whole site
  70. Styling WordPress login page – Can I change the markup on the login page?
  71. Special link for no automatic login (no username and no password)
  72. Modify wp-login.php Labels Conditionally Based On Referring URL
  73. Can’t login with any account – No error message shown
  74. WordPress Login & Register works in localhost but don’t work on server
  75. How to login to wordpress via Cpanel
  76. Hide login page and use wp_login_form on ordinary pages
  77. Make WordPress User Name the Email Address When Register
  78. Custom Field For Login
  79. How can I have customers log in using ONLY customer number? No password
  80. Login user after registration programmatically
  81. How to place wp-login.php in page or page template?
  82. Webpage not found upon entering wrong username and password on custom login form?
  83. Can’t login through wp-login.php on fresh installation
  84. Hide wp-login.php but not the widget
  85. Showing A Menu When Only Users Are Logged In [duplicate]
  86. Logging in takes a few refreshes to show you are logged in, is this a cache issue? [closed]
  87. I can’t login to wordpress dashboard without SSH
  88. Login form- no feedback
  89. Remove login link from Reset Password-screen
  90. Why am I not able to login to the admin
  91. How to disable autocomplete on the wp-login.php page
  92. How can I do customizations on login, registration and password recovery forms?
  93. How to create a private login page for admin.?
  94. Code for Log Out Button Yields Strange URL
  95. wp login password reset
  96. How can I customize the content of the login page?
  97. WordPress giving error when I log in after trying emergency.php
  98. Create custom field for users to check if they agreed to terms
  99. WordPress logs out on protocol switch
  100. WordPress site shows a white page for site/wp_admin. A login returns again to the login screen
Categories login Tags login, mysql, wp-login-form
Allow users to upload attachments to certain posts
ACF in WooCommerce mail template

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress