Here is a simple, quick way to validate required form fields using AJAX, PHP and MySQL. What we’re going to do is display an error message to the right of the required field, and if there are errors, restrict the submit button. And if a user were to skip a required field, or leave it blank, we’ll highlight it along with removing the submit button.
I feel this is useful because it validates on the fly using PHP methods that we may already have in place – there is no need to learn the “Javascript way” to do something that you’ve been doing for a while. I make a few assumptions in this tutorial. The first is that you have a basic understanding of PHP and how to connect to a MySQL database and retrieve records. Along with that, for this tutorial, you’ll need a table setup with usernames and email addresses stored in it; my table will be called “users.” The second is that you have some understanding of how AJAX works. Third is that you have an understanding of CSS and how to define classes and id’s. You could figure these things about by going through this tutorial, but it would be a lot easier on you if you do understand what I laid out.
|