PHP MySQL Tutorial | Form Validation Using PHP
http://www.php-mysql-tutorial.com/wikis/php-tutorial/form-validation-using-php.aspx
What I Learned
Well first off, I learned that trying to mess with PHP when you know almost nothing about it can be a frustrating experience. Still it was a great learning experience and made me stretch a bit to get through it (which is usually painful, but worth it in the end). My original intent was to provide some way of storing the information the user entered into the contact form on my site and fill it back in for them if they had any errors. Thus, I would hopefully prevent many "less than happy" feelings towards me as their entire message just got obliterated. I thought I kind of knew how to make it work, but after a few minutes it was obvious I was going to need help.
The next step of course was to research it. I was excited when I found the above tutorial as it not only gave me an insight to the problem I was having, but also showed me how I could use javascript for my desired functionality and still have php as a backup if it didn't work (i.e. viewers browser doesn't allow javascript). I also learned that there are often easier ways to solve the problem then what you originally came up with. In my instance, I was trying to write code to get the users inputs, somehow write them back into the value property of the input field, and still display the correct error messages. The tutorial showed me a much better way: simply stop the submit action until everything is filled in. I could still send prompts through the use of the alert box, with the extra bonus of using the focus to place the cursor right where the user needs it.
How I Applied it to the Site
I had created a linked javascript file earlier, as I wanted to play around with some things I learned in CIT 203 and jquery. This made it quit easy to paste in the functions from the tutorial. Then came the fun part; the tweaking. First thing I had to do is figure out what the input names and ids that the tutorial used were in its script and match it to those in my php file. I then had to add a few additional "else if" statements to cover the last name field and also the security question. I also had to make sure that I had the form name in there correctly. After a few tests, and a few more tweaks, it finally all worked out perfectly.
Then came the moment of truth after making any cool adjustment to the site, Validation. I indeed ended up with a small error, but it wasn't that bad. It turns out that there is a definite difference between "onClick" and "onclick" (stick with the latter). After a quick typo change, the color turned green and I was off once again to see what else I could stir up in my code.
