Jump to content

AJAX PHP FORM VALIDATIONS


djbuddhi

Recommended Posts

  • 2 months later...

In php script page save as "ajaxError.php" use this alone a

 

 

<?php

$email =$_GET["email"];

if($email)

{

if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))

{

echo "<p align=center><font face='Verdana' size='1' color=red>

<b>^</b> Re-enter the Email

address in the proper format

(username@domain.com).

</font></p>";

}

}

?>

 

in Html page use this..

 

 

 

<input type="text" onblur="return validateEmail(this.value)">

<div id="emailError"></div>

 

in javaScript use this....

 

function validateEmail(str)

{

var xmlHttp;

xmlHttp=getXml();

if(xmlHttp==null)

{

alert("Your Browser Won't support Ajax :(");

return;

}

function Ready()

{

if(xmlHttp.readyState == 4)

{

document.getElementById("emailError").innerHTML=xmlHttp.responseText;

}

}

var url ="ajaxError.php";

url = url + "?email="+str;

xmlHttp.onreadystatechange= Ready

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

}

function getXml()

{

var xmlHttp = null;

try

{

xmlHttp=new XMLHttpRequest();

}

catch(e)

{

try

{

xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");

}

catch(e)

{

xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

}

}

return xmlHttp;s

}

 

thanks

Shang.. :)

Link to comment
Share on other sites

where to put the function in ajax file

 

can mention the place where the function going 2 put

 

 

//Browser Support Code

 

var noOfSubmits = 0;

 

function initForm()

{

noOfSubmits = 0;

 

}

 

function dome()

 

{

noOfSubmits = 0;

 

}

 

 

function clear_data(){

 

document.getElementById("title").value=0;

document.getElementById("surname").value="";

document.getElementById("initials").value="";

document.getElementById("name_d_inintials").value="";

document.getElementById("nic_no").value="";

document.getElementById("FrmDate").value="";

document.getElementById("comp_usb_div").value="";

document.getElementById("emp_no").value="";

document.getElementById("add_1").value="";

document.getElementById("add_2").value="";

document.getElementById("town_city").value="";

document.getElementById("province").value="";

 

 

 

if (document.getElementById("chkagree").checked ){

        document.getElementById("chkagree").checked = false;

document.getElementById('row11').style.display="none";                       

                        document.getElementById('row12').style.display="none";

                        document.getElementById('row13').style.display="none";

 

}

 

document.getElementById("mob_no").value="";

document.getElementById("office_telno").value="";

document.getElementById("res_tel_no").value="";

document.getElementById("email_add").value="";

 

 

 

 

 

 

}

 

 

function ajaxFunction(){

var ajaxRequest;  // The variable that makes Ajax possible!

 

try{

// Opera 8.0+, Firefox, Safari

ajaxRequest = new XMLHttpRequest();

} catch (e){

// Internet Explorer Browsers

try{

ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try{

ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e){

 

alert(" Your browser Broke ..!Pls Try Again ...!");

return false;

}

}

}

// Create a function that will receive data sent from the server

ajaxRequest.onreadystatechange = function(){

if(ajaxRequest.readyState == 4){

var ajaxDisplay = document.getElementById('div_Add_emp_info');

ajaxDisplay.innerHTML = ajaxRequest.responseText;

}

 

 

 

 

 

 

 

 

}

 

          var com_tbl_id= document.getElementById("hdd_comp_id").value;

  var title=document.getElementById("title").value;

  var surname= document.getElementById("surname").value;

 

  var inintials= document.getElementById("initials").value;

  var name_d_initials= document.getElementById("name_d_inintials").value;

  var nic_no= document.getElementById("nic_no").value;

  var date_of_birth= document.getElementById("FrmDate").value;

  var sub_com_name=document.getElementById("comp_usb_div").value;

 

  var emp_no = document.getElementById("emp_no").value;

  var address_1= document.getElementById("add_1").value;

  var address_2= document.getElementById("add_2").value;

  var tow_city= document.getElementById("town_city").value;

  var province= document.getElementById("province").value;

  var agree= document.getElementById("chkagree").value;

  var new_add_1= document.getElementById("new_add_1").value;

  var new_add_2= document.getElementById("new_add_2").value;

  var new_town_city= document.getElementById("new_town_city").value;

  var mob_no= document.getElementById("mob_no").value;

  var office_telno= document.getElementById("office_telno").value;

  var res_telno= document.getElementById("res_tel_no").value;

  var emailno= document.getElementById("email_add").value;

 

 

 

    noOfSubmits++;

 

if(noOfSubmits>1)

{

alert("Submission already done. Please wait while system is updating..!");

return false;

}

 

else{

  emailno

//var queryString = "?setle_agent_name="+settle_argent +"&set_address="+set_address+"&set_ag_telno="+set_telno +"&set_ag_fax_no="+set_faxno +"&set_ag_email_no="+set_email +"&set_ag_web="+set_web;

var queryString = "?surname="+surname +"&comp_tblid="+com_tbl_id+"&initilas="+inintials +"&p_title="+title +

"&name_denote_by_initials="+name_d_initials  +"&NIC_NO="+nic_no +"&DOb="+date_of_birth

+"&sub_com_name="+sub_com_name +"&p_emp_no="+emp_no

+"&adress1="+address_1 +"&adress2="+address_2 + "&towncity="+tow_city

+ "&province="+province + "&my_agree="+agree + "&new_address1="+new_add_1

+ "&new_address2="+new_add_2 + "&new_town_city="+new_town_city

+ "&office_telno="+office_telno + "&mob_no="+mob_no

+ "&residance_telno="+res_telno + "&email="+emailno;

 

ajaxRequest.open("GET", "ajax_add_employee_infor.php" + queryString, true);

ajaxRequest.send(null);

clear_data();

 

 

}

}

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.