php form validation using ajax 
June 24th, 2009, 05:57 AM
| | Familiar Sight | | Join Date: Jan 2008
Posts: 196
| | |
I' developing web site with php and postgres. I want to validate php forms using ajax. I'm new to ajax and tried to several examples. But still I couldn't get it. Could someone please tell me a complete example in php and ajax?
| 
June 24th, 2009, 08:29 AM
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,102
Provided Answers: 1 | | | re: php form validation using ajax
have a look here for an example where AJAX and php work together ... simply post back in case you have specific problems with your code.
kind regards
| 
June 25th, 2009, 06:13 AM
|  | Familiar Sight | | Join Date: May 2009 Location: Wellington, New Zealand
Posts: 152
| | | re: php form validation using ajax
you try some thing first and then ask for help.. better to have more specific.. lots of tutorial and example online ajax form validation | 
June 25th, 2009, 01:05 PM
| | Familiar Sight | | Join Date: Jan 2008
Posts: 196
| | | re: php form validation using ajax
Thanx for everyone. Now I'm little bit ok with ajax. These are my php form and ajax file. I want to check array values in php file using ajax function. I tried just one variable and it didn't work. Could you please tell me when I went wrong?
test.php
====== -
<?php
-
-
$array = array('Name'=>'FullName','Gender'=>'Gender','PhnNo' =>'PhoneNumber','Email' =>'EmailAddress','Address' =>'Address');
-
-
?>
-
-
<form action="test.php" method="post" id="test" >
-
.....
-
<tr><td height="24" >Full Name</td>
-
<td colspan="2"><input type="text" name="Name" size="40"/></td>
-
</tr>
-
<tr>
-
<td>Gender</td>
-
<td width="69"><input name="Gender" type="radio" value="1" /> Male</td>
-
-
<td width="297" ><input name="Gender" type="radio" value="2" />Female </td>
-
</tr>
-
-
<tr>
-
<td>Phone Number</td>
-
<td colspan="2"><input type="text" name="PhoneNumber" /></td>
-
</tr>
-
-
<tr>
-
<td>Email Address</td>
-
<td colspan="2"><input type="text" name="Email" /></td>
-
</tr>
-
<tr>
-
<td>Address</td>
-
<td colspan="2"><input type="text" name="Address" size="40" /></td>
-
</tr>
-
-
<tr>
-
-
<td colspan="2" align="right">
-
<input name="Submit" value="Submit" id="Submit" src="../images/Submit.jpg" type="image" alt="add" height="30" width="73" onclick="add();" />
-
</td>
-
</tr>
-
</form>
-
.....
-
test.js
====== -
function ajax() {
-
var request;
-
try {
-
request=new XMLHttpRequest();
-
}
-
catch (e) {
-
try {
-
request=new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e) {
-
try {
-
request=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
catch (e) {
-
alert("Your browser does not support AJAX!");
-
return false;
-
}
-
}
-
}
-
return request;
-
}
-
-
-
function add(Name,Gender,PhnNo,Email,Address){
-
//alert ('test')
-
if (PhnNo){
-
PhnNo= document.getElementById(PhnNo).value
-
var regex = /^\d{11}$/;
-
if( !PhnNo.match(regex) )
-
return "Number is incorrect!!";
-
}
-
-
}
-
-
Last edited by acoder; June 25th, 2009 at 02:52 PM.
Reason: Changed [quote] to [code] tags
| 
June 25th, 2009, 02:59 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,517
Provided Answers: 12 | | | re: php form validation using ajax
Your call to the add() function doesn't have any parameters, so the function won't do anything. There's no reference to the Ajax function. If you want to use PHP code to validate, then there's no point in using JavaScript validation as well. Make an Ajax request to your PHP validation script instead.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,652 network members.
|