Ajax form validating foroum and community dating site
I think the most important aspects of building and processing a form is how you validate data, help the visitor with tips, how you make it easy to understand what’s required and optional and how it performs after hitting the submit button. Well, let’s suppose you have a huge form in front of you (try opening an account on a dating site for example – the whole process of 3 pages is full of forms)…you complete all of them and you hit submit.
You didn’t knew that free email accounts such as yahoo, hotmail or google are not allowed because the webmaster forgot to mention or you simply didn’t noticed the small size 1 font telling you that. This is ok and we’re used to it but imagine this horrible scenario that is present on thousands of websites: you’re supposed to fill the whole form all over again because it didn’t remembered your data. I’ll tell you what: what 80% will do is leave unless they need that membership.
Using if, elseif and else you’re able to achieve something similar only that (in case we have more than 1 error) the messages will be displayed one at a time.
In case the result is yes, we perform a loop to display all of them on different lines: In case not, there’s no need for a loop since we can show a success message in only one case (if everything passed our ajax validation).
I’ve added a comment there (//do something here—-store to db, send email), it’s the place where you should place your code for storing the info to the database, sending confirmation emails etc.
The domready event which is way more faster than the old window onload.
The form is ready to validate using AJAX in no time and all that I’ve mentioned above sits on a 23kb js file. Let’s move to the php file where the main “engine” sits.