skip to content »

Validating date server side in php

These elements can then be referenced in the XML file that is returned by the Ajax call.

When all fields have been validated the form will be able to be submitted.Samples of the XML files returned in each case can be found below.These are generated by PHP, but another server-side scripting language would also work.The on Submit handler for the form requires also that a value be entered in all fields before the form can be submitted.This article follows on from Web Services using XMLHttp Request (Ajax) and demonstrates the usage of the Ajax class for validating online forms.This example uses the Java Script XMLHttp Request object and PHP server-side scripting to check that the Email address entered is valid (at least that it matches a particular regular expression) and that the Age lies between 16 and 100.

As the form is completed, the values are passed immediately to the server as POST variables, the server calculates a result, passing back an XML file which is then parsed to trigger various actions on the page as you will see.

If you enter an invalid Email address, or a value for Age outside the specified range, a .

The function check Form(form) { if(value == "") { alert("Please enter your Name in the form"); focus(); return false; } if( == "" || !

this.valid_email.checked) { alert("Please enter a valid Email address");; return false; } if(value == "" || !

this.valid_age.checked) { alert("Please enter an Age between 16 and 100"); focus(); return false; } alert("Success!

The form has been completed, validated and is ready to be submitted..."); return false; } to the input box ('email'), to the associated checkbox ('valid_email) and to the DIV where the feedback text is to appear ('rsp_email').