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?
php form validation using ajax
Collapse
X
-
you try some thing first and then ask for help.. better to have more specific.. lots of tutorial and example online ajax form validationComment
-
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
======
[code=php]
<?php
$array = array('Name'=>' FullName','Gend er'=>'Gender',' PhnNo' =>'PhoneNumber' ,'Email' =>'EmailAddress ','Address' =>'Address');
?>
<form action="test.ph p" method="post" id="test" >
.....
<tr><td height="24" >Full Name</td>
<td colspan="2"><in put type="text" name="Name" size="40"/></td>
</tr>
<tr>
<td>Gender</td>
<td width="69"><inp ut 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"><in put type="text" name="PhoneNumb er" /></td>
</tr>
<tr>
<td>Email Address</td>
<td colspan="2"><in put type="text" name="Email" /></td>
</tr>
<tr>
<td>Address</td>
<td colspan="2"><in put 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>
.....
[/code]
test.js
======
Code: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!!"; } }Comment
-
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.Comment
Comment