I am Asif Khalyani. I am software Engineer. PHP and ajax free script download site phpasks. User can download free php script.
This degradable form validation demo verifies the form at the server side on the classic form submit, and also implements AJAX validation while the user navigates through the form.
Degradable AJAX Form Validation
Doing a final server-side validation when the form is submitted is always a must. If someone disables JavaScript in the browser settings, AJAX validation on the client side won't work, exposing sensitive data, and thereby allowing an evil-intended visitor to harm important data back on the server (for example, through SQL injection). Always validate user input on the server!
This form validation application validates a registration form, using both AJAX validation (client side) and typical server-side validation:
* AJAX-style (on the client), when each form field loses focus (onblur). The field's value is sent to the server, which validates the data and returns a result (0 for failure, 1 for success). If validation fails, an error message will unobtrusively show up and notify the user about the failed validation.
* PHP-style (on the server), when the entire form is submitted. This is the usual validation you would do on the server, by checking user input against certain rules. If no errors are found and the input data is valid, the browser is redirected to a success page. If validation fails, however, the user is sent back to the form page with the invalid fields highlighted.
Both AJAX validation and PHP validation check the entered data against these rules:
* Username must not already exist in the database
* Name field cannot be empty
* A gender must be selected
* Email address must be written in a valid email format, such as xyz@domain.com
* Phone number must be written in standard US form: +xx xxxxxxxxx
Thread-Safe AJAX
A piece of code is thread-safe if it functions correctly during simultaneous execution by multiple threads. In this exercise, we need to make an asynchronous request to the server to validate the entered data every time the user leaves an input box or changes a selection.
The hidden danger behind this technique is only revealed if the user moves very quickly through the input fields, or the server connection is slow; in these cases, the web application would attempt to make new server requests through an XMLHttpRequest object that is still busy waiting for the response to a previous request (this would generate an error and the application would stop functioning properly).
Depending on the circumstances at hand, the ideal solution to this problem may be:
* Create a new XMLHttpRequest instance for every message you need to send to the server. This method is easy to implement, but it can degrade server's performance if multiple requests are sent at the same time, and it doesn't guarantee for the order in which you receive the responses.
* Record the message in a queue and send it later when the XMLHttpRequest object is able to make new requests. The requests are made in the expected order. Using a queue is particularly important in applications where the order of the messages is important.
* Schedule to automatically retry making the request after a specified amount of time. This method is similar to the one with the queue in that you don't make more than one server request at a time, but it doesn't guarantee for either the order in which the requests are made, or for the order in which the responses are received.
* Ignore the message.
In this form validation exercise, we use a message queue. When the user leaves an input element, a message to validate its value is added to the queue. When the XMLHttpRequest object is clear to make a new request, it takes the first message from the queue.
The queue is a First-In, First-Out (FIFO) structure, which guarantees that the messages are sent in the proper order. To get a feeling about how this works, go to the demo page, and press tab quickly multiple times, and then wait to see how the validation responses show up one by one.
The complete AJAX and PHP tutorial features even more AJAX web development examples.
Downlaod code
PHP and Ajax submit form
- Related Videos
- Related Articles
- Ask / Related Q&A
- Upload Image Without Refresh Page - Asynchronous Image File Upload Without Ajax
- Ajax Form Validation and Thread-safe Ajax
- Crop Image File Size, Width & Height Using Php Script
- Adding an Ajax Web Photo Gallery to Your Website for Amateurs. (based on My Own Experience)
- Learn How to Store and Share Your Files by using Ajax
- Save time with ScriptArtist PHP and AJAX code generator!
- Coppermine—A Popular Multi-lingual Image Gallery
- Embed Documents on your website or Blog through unique Software




Packt Publishing's new 'Ext JS 3.0 Cookbook'
By: Amit Sharma | 13/11/2009Authored by Jorge Ramon, the Ext JS 3.0 Cookbook contains step-by-step recipes for building impressive rich internet applications using the Ext JS JavaScript library.
GROUP BY IN XQUERY
By: Anuj Tripathi | 13/11/2009This article will provide you to implement GROUP BY clause in XQUERY with the code.
Java Developers and the power of Java
By: jacklin | 13/11/2009Article explaining the security steps Java developers can take for JAR files while developing application with Java platform.
Sending SMS Alerts in SharePoint 2010 over Office Mobile Service Protocol (OMS)
By: Virtosoftware | 12/11/2009Finally it's possible to send SMS directly from SharePoint to mobile phones. This feature was only available in some add-on components before.
Forbidding the Clipboard for the specified process
By: Apriorit Inc. | 11/11/2009Though the Clipboard is one of the fundamental parts of the Windows operating system, there is little information about how it works, especially in the low level. In this article, I’m going to tell you something about the Clipboard internals by showing how you can forbid access to it.
How to save money from fixing computer?
By: janson | 11/11/2009Are you familiar with these problems in your computer below? Mysterious errors, crashes and restarts Sluggish internet and download speeds Trouble loading songs, movies and programs Do you tire of frequently bothering friends for help, or worse, paying a professional to fix your computer? Like a car, without regular maintenance computers begin to accumulate errors that cause slowdowns, crashes and even potential system failure.
Learn Java Easily With an IDE
By: Alberto Pareja-Lecaros | 11/11/2009Want to learn Java even more quickly than you currently are? IDE's are not just for professionals; learn how you can use an IDE to teach yourself Java even more easily, even if you're an absolute beginner! There are many advantages to using an IDE, why torture yourself by using a standard text editor when you can use the power of an IDE to learn Java even more easily?
Benefits of digital photography-why digital photography is booming?
By: hdrmiar | 11/11/2009This article shows you some benefits of digital photography and makes an outlook of future development of photography.
Easy Ajax Inline Text Edit 2.0
By: Asif Khalyani | 09/09/2008 | ProgrammingA small piece of javascript reads al SPAN tags, checks if it has class="editText" and a id=. If that is true, it adds a onclick function. That onclick function will create a textfield or input (depending on the size of the editable text). Someone has the ability to edit the field. When the text field is blurred, it will read the contents, and starts a XMLHttpRequest and ‘sends’ the content + fieldname + any set vars to an update file.
Crop Image File Size, Width & Height Using Php Script
By: Asif Khalyani | 03/07/2008 | ProgrammingCropping and resizing your images for the Web is a common technique for creating smaller thumbnail images that download quickly.
Ajax Form Validation and Thread-safe Ajax
By: Asif Khalyani | 03/07/2008 | ProgrammingThis is the PHP and AJAX form validation application you can create AJAX and PHP: Building Responsive Web Applications.
Upload Image Without Refresh Page - Asynchronous Image File Upload Without Ajax
By: Asif Khalyani | 23/06/2008 | ProgrammingI suppose it is neccessary to bring a little bad news to Ajax at this point, it is not possible to process a file upload through the XMLHtrtpRequest Object. The reason of this is that javascript has no access to your computer's file system.