473,606 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ajax validation

250 Contributor
I have a web page developed using php and postgres. There I have a page for user administration( add user). If user fill all information and click submit button I want to send those values to ajax file and validate and insert to the DB. I passed value to the ajax file and I want to send validated values to php file to insert to the DB. How can I do that? Plase help me.
This is my php file.

Expand|Select|Wrap|Line Numbers
  1. if(isset($_POST['submit'])){
  2.     $array = array('FullName'=>'FullName','Gender'=>'Gender','PhnNo' =>'PhoneNumber',    'Email' =>'EmailAddress',);
  3.     foreach ($array as $key => $val)
  4.     $$key = $_POST[$val];
  5.  
  6.         $pgsql = "insert into \"User\" ( \"Name\" ,  \"Phone\" ,  \"PtntEmail\",\"Gender\" )
  7. VALUES ('$FullName',  '$PhnNo',  '$Email','$Gender');"; 
  8.  echo $pgsql;
  9.     $result = pg_query($dbconn , $pgsql);
  10.     if (!$result) {
  11.          die("Error in SQL query: " . pg_last_error());
  12.      }
  13.  
  14.         echo "Data successfully inserted!";
  15.      }
  16.  
  17.     ?>            <form name="user.php" id="user.php" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
  18.                       <tr>
  19.                     <td height="24" colspan="3" ><!--DWLayoutEmptyCell-->&nbsp;</td>
  20.                 </tr>
  21.                   <tr>
  22.                     <td height="24" >Full Name*</td>
  23.                     <td colspan="2"><input type="text" name="FullName"  size="40" ></td>
  24.                   </tr>
  25.  
  26.                   <tr>
  27.                     <td>Gender</td>
  28.                     <td width="69"><input name="Gender" name="Male" type="radio" value="1"/> Male</td>
  29.  
  30.                     <td width="297"  ><input name="Gender" name="Female" type="radio" value="2" />Female&nbsp;</td>
  31.                   </tr>
  32.  
  33.                   <tr>
  34.                     <td>Phone Number*</td>
  35.                     <td colspan="2"><input type="text" name="PhoneNumber" /></td>
  36.                   </tr>
  37.  
  38.                   <tr>
  39.                     <td>Email Address</td>
  40.                     <td colspan="2"><input type="text" name="EmailAddress" /></td>
  41.                   </tr>
  42.  
  43.                   </tr>
  44.  
  45.                   <tr>
  46.                     <td>&nbsp;</td>
  47.                     <td colspan="2" align="right">
  48.  
  49.                 <input id="submit" src="submit.jpg" type="image"  alt="submit" height="30"  width="73" onclick="javascrpit:pages(); return false"  />
  50.  
  51.                     <input id="Cancel" src="Cancel.jpg" type="image"  alt="cancel" height="30"  width="73" />    
  52.  
This is ajax page
Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject() {
  2.     var request;
  3.     try {
  4.         request=new XMLHttpRequest();
  5.     }
  6.     catch (e) {
  7.         try {
  8.             request=new ActiveXObject("Msxml2.XMLHTTP");
  9.         }
  10.           catch (e) {
  11.             try {
  12.                 request=new ActiveXObject("Microsoft.XMLHTTP");
  13.             }
  14.             catch (e) {
  15.                 alert("Your browser does not support AJAX!");
  16.                 return false;
  17.             }
  18.         }
  19.     } 
  20.     return request;
  21. }
  22.  
  23.  
  24. function pages(){
  25. var FullName =document.getElementById('FullName').value;
  26.  
  27. }
  28.  
  29.  
Jul 16 '09 #1
1 2026
daniel2335
49 New Member
It would be probably better to use the form for places like this if there is going to be a bit of data.

This is one of my ajax functions..

Expand|Select|Wrap|Line Numbers
  1. function displayMiningSelectDialog(astID)
  2. {
  3.     miningDialogHttp = getXMLHttp(); 
  4.     if(miningDialogHttp == null)
  5.     {
  6.         alert ("Browser does not support HTTP Requests");
  7.         return;
  8.     }
  9.     var domain = document.domain;
  10.     var url="http://" + domain + "/GAME/PHP/Scan/ScanXMLhttp.php";
  11.     url=url+"?miningDialog=1&astID=" + astID + "&sid="+Math.random();
  12.     miningDialogHttp.open("GET",url,true);
  13.     miningDialogHttp.onreadystatechange=displayMiningSelectDialogResponse;
  14.     miningDialogHttp.send(null);
  15. function displayMiningSelectDialogResponse() 
  16.     if (miningDialogHttp.readyState==4 || miningDialogHttp.readyState=="complete")
  17.     {
  18.         eval(miningDialogHttp.responseText);
  19.     }
  20. }
Jul 16 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
5783
by: Mihir | last post by:
Hi There, I've problem while I submit a button where I used AJAX, I created simple page which will search the customer name from database using AJAX. Once I search customer ID i need to search order related to that customers. So on my page I've Search Button(Image Button).. Now if I click on search button without selecting the customer from the result which I get from AJAX method then it will work fine but if I select a customer ID from...
1
1864
by: AECL_DEV | last post by:
Hello Everyone, Ive seen alot of people saying that the best way to AJAX Validate a form is through the submit button, because validation should be synchronous. Im wondering, is there any good way to validate a form field by field like AJAX would do, but to keep it synchronous? i.e. one action, one validation. Thanks,
5
2206
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only parts of your page. But in my application there are situation when I first notice on the server -- so AFTER sending an AJAX request -- that I have to update the complete page instead of only some parts. And what do I do now???
1
1931
by: John Chan | last post by:
Hi, Im doing a maintenance application in ajax and coldfusion at work on IE6 exclusively. I have a save button on each form and i have to do various validations server side and on client side when the user clicks save i.e check that user exists in table, check users password is the same as password in table, check password is valid, check that logged in user is a super user etc etc to get the correct error message. Different forms may or...
3
3489
by: Sandman | last post by:
So, I've used ajax for quite some time for different stuff. Mostly I just feed a funktion I made with the ID of the DIV that should be updated with the output from page XXX.php Now I want to have a standard funktion to set a JS variabel to the output of a page. I am doing a date validation thing, which is done in PHP. So this is how far I've come so far: function ajaxresults(url){ var ajax = createAjaxObject();
5
3215
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The javascript method will do the form validation for each field one by one. For each field, an XMLHttpRequst will be made to a PHP file and get the return, either set an error field (<span>'s innerHTML) or leave it empty. Then I'll check the error field...
7
3597
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
3
2606
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to solve the problem. Here is the previous post http://bytes.com/forum/thread798289.html Trying to trace the problem I have written a code (Separate from The Form Validation) which sends 300 requests with an interval of 10 miliseconds and displays the...
16
2192
by: ashwinkumar18 | last post by:
hi, am very new to ajax and js . i tried using ajax for server validation in my jsp. i also used js for client side validation i have my js script for client side validation in a seperate file. i embedded the ajax code in the jsp itself. the client side validation and the ajax code are working when i use them seperately. but when i try to use them both , the client side validation is not taking place at all. my page is directly...
3
2100
pradeepjain
by: pradeepjain | last post by:
hii guys , I wanna share a very gud ajax validation script with php... Ajax Form Validation - sForm | chains.ch weblog I am very new to ajax .So i wanna small help....i want to improve that script with adding checkbox,radiobutton validation and dropdown list validation . but i am not able to do it.....any one can add his/her code into that ajax script..tht i can have a look at it.. And i have found a small bug in tht script...
0
8031
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7962
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8456
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8443
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6792
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5971
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3945
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.