Ajax Contact Form Help Please

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Sep 2008
Posts: 2
Reputation: Melissa34 is an unknown quantity at this point 
Solved Threads: 0
Melissa34 Melissa34 is offline Offline
Newbie Poster

Ajax Contact Form Help Please

 
0
  #1
Sep 14th, 2008
Hi
I've been following a tutorial that describes 'Hijax' from the book Bulletproof Ajax and it is not that clear exactly where the sections of code go...can anyone please help with this and troubleshoot??
(I am a complete novice with this and it's taken me ages to type it all out!!) Help appreciated,
Many thanks
Melissa

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <script type="text/javascript" src="ajax.js"></script>
  6. <title>Contact Us</title>
  7. </head>
  8.  
  9. <body>
  10. <h1>Contact Us</h1>
  11. <div id="container">
  12. <?php include "formlogic.php";?>
  13. </div>
  14. </body>
  15. </html>

Formlogic.php is....
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form method="post" id ="contactform" action="">
  2. <p>
  3. <label for="name">Name</label>
  4. <input type="text" name="name" id="name" value="" />
  5. </p>
  6. <p>
  7. <label for="email">Email</label>
  8. <input type="text" name="email" id="email" value="" />
  9. </p>
  10. <p>
  11. <label for="message">Message</label>
  12. <textarea name="message" id="message" cols="30" rows="10">
  13. </textarea>
  14. </p>
  15. <p>
  16. <input type="submit" name="submit" value="Submit" />
  17. </p>
  18. </form>

And ajax.js is...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function sendData(data) {
  2. var request = getHTTPObject();
  3. if (request) {
  4. request.onreadystatechange = function() {
  5. parseResponse(request);
  6. };
  7. request.open( "POST", "formlogic.php", true);
  8. request.setRequestHeader("Content-Type",
  9. "application/x-www-form-urlencoded");
  10. request.send(data);
  11. return true;
  12. } else {
  13. return false;
  14. }
  15. }
  16. window.onload = prepareForm;
  17. function prepareFrom() {
  18. if(!document.getElementById) {
  19. return;
  20. }
  21. if(!document.getElementById("contactform")) {
  22. return;
  23. }
  24. document.getElementById("contactform").onsubmit =
  25. function() {
  26. var data=" ";
  27. for(var i=0; i<this.elements.length; i++) {
  28. data+= this.elements[i].name;
  29. data+= "=";
  30. data+= escape(this.elements[i].value);
  31. data+= "&";
  32. }
  33. return !sendData(data);
  34. };
  35. }
  36. function parseResponse(request) {
  37. if (request.readyState == 4) {
  38. if (request.status == 200 || request.status == 304) {
  39. var container = document.getElementById("container");
  40. container.innerHTML = request.responseText;
  41. prepareForm();
  42. }
  43. }
  44. }
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 454
Reputation: Atli is on a distinguished road 
Solved Threads: 56
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: Ajax Contact Form Help Please

 
0
  #2
Sep 14th, 2008
Why do you have AJAX send the data to the formlogic.php script?

You need to have a script that can process the data you are sending, and have AJAX send the data there.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 2
Reputation: Melissa34 is an unknown quantity at this point 
Solved Threads: 0
Melissa34 Melissa34 is offline Offline
Newbie Poster

Re: Ajax Contact Form Help Please

 
0
  #3
Sep 16th, 2008
Hi
thanks for the response...eventually I found the code online http://www.bulletproofajax.com/code/

The chapter in the book was called Hijax - using javascript,php, html....I'm not sure what exactly the javascript does, seems to process the form.

Thanks

Mel
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC