473,698 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

AJAX contact form

9 New Member
Ok so I found an ajax contact form script but i can't get the b****** to work. I made a bunch of alterations to it and it didn't work so i replaced everything with the original and it still didn't work...dunno why, but anyhow. The form appears after a delay on the page in a hidden DIV. The original form just had name, email and message, but i have to add a few questions to it so i did and i also added some code from another script i found to alter the body text. I probably screwed it all up but i'm no expert so please help.

All the code is in a single php file that's called as an include in the actual page. It displays just fine but when i go to submit it just says "please wait" and never sends an email.

Expand|Select|Wrap|Line Numbers
  1. <?
  2. if(!isset($rnd) || !isset($name) || !isset($email) || !isset($realtor) || !isset($when) || !isset($selling)) {
  3.     showform();
  4. } else {
  5.     processform();
  6. }
  7.  
  8. $Body = "";
  9. $Body .= "Name: ";
  10. $Body .= $Name;
  11. $Body .= "\n";
  12. $Body .= "Email: ";
  13. $Body .= $email;
  14. $Body .= "\n";
  15. $Body .= "Working with a Realtor: ";
  16. $Body .= $Realtor;
  17. $Body .= "\n";
  18. $Body .= "How soon they are looking to buy or rent: ";
  19. $Body .= $When;
  20. $Body .= "\n";
  21. $Body .= "Selling their home: ";
  22. $Body .= $Selling;
  23. $Body .= "\n";
  24.  
  25. function processform(){
  26.     global $name, $email, $realtor, $when, $selling, $Body;
  27.  
  28.     $email_to1 = "shadedjg@hotmail.com"; // enter your email here
  29.     $email_from1 = $mail;
  30.     $email_to2 = $mail;
  31.     $email_from2 = $email_to1;
  32.     $email_subject = "Contact Form: ".stripslashes($subject);
  33.     $email_message = "Please find below a message submitted by '".stripslashes($name);
  34.     $email_message .="' on ".date("d/m/Y")." at ".date("H:i")."nn";
  35.     $email_message .="--------- START OF SUBMITTED MESSAGE ---------nn";
  36.     $email_message .= stripslashes($Body);
  37.     $email_message .="nn--------- END OF SUBMITTED MESSAGE ---------nn";
  38.  
  39.     $confirmation_subject = "Thank you for your message";
  40.     $confirmation = "This is to confirm we have received your message....";
  41.  
  42.     // SEND EMAIL TO email_to2 - confirmation
  43.     $headers = 'From: '.$email_from2."rn" .
  44.    'Reply-To: '.$email_from2."rn" .
  45.    'X-Mailer: PHP/' . phpversion();
  46.  
  47.     mail($email_to2, $email_subject, $confirmation, $headers);
  48.  
  49.     // SEND EMAIL TO email_to1 - message to you!!
  50.     $headers = 'From: '.$email_from1."rn" .
  51.    'Reply-To: '.$email_from1."rn" .
  52.    'X-Mailer: PHP/' . phpversion();
  53.  
  54.     mail($email_to1, $email_subject, $email_message, $headers);
  55.  
  56.     echo "Thank You.";
  57.     die();
  58. } // end processform()
  59.  
  60. function showform() {
  61. ?>
  62. <STYLE type="text/css">
  63. div.row {
  64.   clear:both;
  65.   }
  66. div.row span.label {
  67.   float: left;
  68.   width: 60px;
  69.   text-align: right;
  70.   }
  71. div.row span.formw {
  72.   float: right;
  73.   width: 220px;
  74.   text-align: left;
  75.   }
  76. div.row span.left {
  77.   float: left;
  78.   text-align: left;
  79.   font-weight: bold;
  80.   color: #fff;
  81.   width: 49%;
  82.   }
  83. div.row span.right {
  84.   float: right;
  85.   text-align: right;
  86.   font-weight: bold;
  87.   color: #fff;
  88.   width: 49%;
  89.   }
  90. div.row span.submit{
  91.   width:280px;
  92.   text-align:center;
  93. }
  94. #form{
  95.     width: 300px;
  96.     height: 500px;
  97.     background-color: #f6f6f6;
  98.     border: 1px dotted #666;
  99.     padding: 2px;
  100.     margin: 0px auto;
  101.     position: relative;
  102. }
  103. #confirmation{
  104.     width: 300px;
  105.     height:220px;
  106.     background-color: #f6f6f6;
  107.     border: 1px dotted #666;
  108.     padding: 2px;
  109.     margin: 0px auto;
  110.     text-align: center;
  111.   font-weight: bold;
  112. }
  113. </STYLE>
  114. <script type="text/javascript">
  115. <!--
  116. var http = createRequestObject();
  117. var areal = Math.random() + "";
  118. var real = areal.substring(2,6);
  119.  
  120. function createRequestObject() {
  121.     var xmlhttp;
  122.     try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
  123.   catch(e) {
  124.     try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
  125.     catch(f) { xmlhttp=null; }
  126.   }
  127.   if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  128.       xmlhttp=new XMLHttpRequest();
  129.   }
  130.     return  xmlhttp;
  131. }
  132.  
  133. function sendRequest() {
  134.     var rnd = Math.random();
  135.     var name = escape(document.getElementById("name").value);
  136.     var email = escape(document.getElementById("email").value);
  137.     var realtor = escape(document.getElementById("realtor").value);
  138.     var when = escape(document.getElementById("when").value);
  139.     var selling = escape(document.getElementById("selling").value);
  140.  
  141.     try{
  142.     http.open('POST',  'ajax_contact.php');
  143.     http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  144.     http.onreadystatechange = handleResponse;
  145.         http.send('name='+name+'&email='+email+'&realtor='+realtor+'&when='+when+'&selling='+selling+'&rnd='+rnd);
  146.     }
  147.     catch(e){}
  148.     finally{}
  149. }
  150.  
  151. function check_values() {
  152.     var valid = document.getElementById("valid").value;
  153.     if(real !== valid) {
  154.         alert("Anti-Bot check failed.....nPlease enter the 4 digits as they appear.");
  155.         return false;
  156.     }
  157.  
  158.     var name = document.getElementById("name").value;
  159.     var email = document.getElementById("email").value;
  160.     var realtor = document.getElementById("realtor").value;
  161.     var when = document.getElementById("when").value;
  162.     var selling = document.getElementById("selling").value;
  163.     if(trim(name) == "" ||
  164.         trim(email) == "" ||
  165.         trim(realtor) == "" ||
  166.         trim(when) == "" ||
  167.         trim(selling) == "") {
  168.             alert("Please complete all fields");
  169.     } else {
  170.         if(isEmail(email)) {
  171.             document.getElementById("submit").disabled=true;
  172.             document.getElementById("submit").value='Please Wait..';
  173.             sendRequest();
  174.         } else {
  175.             alert("Email appears to be invalid.nPlease check.");
  176.             document.getElementById("email").focus();
  177.             document.getElementById("email").select();
  178.         }
  179.     }
  180. }
  181.  
  182. function handleResponse() {
  183.     try{
  184.     if((http.readyState == 4)&&(http.status == 200)){
  185.         var response = http.responseText;
  186.       document.getElementById("confirmation").innerHTML = response;
  187.       document.getElementById("confirmation").style.display ="";
  188.       document.getElementById("form").style.display = "none";
  189.         }
  190.   }
  191.     catch(e){}
  192.     finally{}
  193. }
  194.  
  195. function isUndefined(a) {
  196.    return typeof a == 'undefined';
  197. }
  198.  
  199. function trim(a) {
  200.     return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
  201. }
  202.  
  203. function isEmail(a) {
  204.    return (a.indexOf(".") > 0) && (a.indexOf("@") > 0);
  205. }
  206.  
  207. function botCheckInfo() {
  208.     alert("To prevent automatic programs (bots)nfrom submitting spam through this form,nwe have added a simple validationncheck to the form. You must enter nthese 4 digits in the box provided innorder to submit the form.");
  209. }
  210.  // -->
  211.  </script>
  212.  
  213. <?
  214. } // end showform()
  215. ?>
  216.     <div id="form">
  217. <form>
  218. <div class="row"><span class="label">Name:</span>
  219.     <span class="formw"><input type="text" id="name" size="30" /></span></div>
  220. <div class="row"><span class="label">Email:</span>
  221.     <span class="formw"><input type="text" id="email" size="30" /></span></div>
  222. <div class="row"><span class="label">Are your currently working with a Realtor?:</span>
  223.     <span class="formw"><select id="realtor">
  224.           <option value="Yes">Yes</option>
  225.           <option value="No">No</option>
  226.         </select></span></div>
  227. <div class="row"><span class="label">How soon are you looking to buy, sell or rent?:</span>
  228.     <span class="formw"><select id="when">
  229.           <option value="Now">Now</option>
  230.           <option value="Within a few months">Within a few months</option>
  231.           <option value="Within 6 months">Within 6 months</option>
  232.           <option value="Within a year">Within a year</option>
  233.           <option value="Not sure">Not sure</option>
  234.         </select></span></div>
  235. <div class="row"><span class="label">Do you have to sell your home?:</span>
  236.     <span class="formw"><select id="selling">
  237.           <option value="Yes">Yes</option>
  238.           <option value="No">No</option>
  239.         </select></span></div>
  240. <div class="row"><a href="javascript:botCheckInfo()">Anti-bot check</a>. Enter Digits '<b><script language="javascript">document.write(real)</script></b>' below:</div>
  241. <div class="row"><input type="text" id="valid" size="15" /></div>
  242. <div class="row">&nbsp;</div>
  243. <div class="row">
  244.     <input type="button" value="Submit" id="submit" onClick="return check_values();"></div>
  245. <div id="confirmation" style="display:none"></span></div>
  246. </form>
  247.  
  248. </div>
Dec 8 '07
12 3830
colt28
9 New Member
I finally figured it out. It was ONE character. The line where the javasript sends the variables to the php portion had a '$' instead of '&' on one of them. Prime example of why i'm not a coder :oP

Thanks for all your help :o) Much appreciated.
Dec 23 '07 #11
gits
5,390 Recognized Expert Moderator Expert
*lol* ... nope ... believe me ... such errors are common ... lasty i had such a problem at work ... a colleague searched for a bug and we did together ... it lasts us two hours to find out a mistyped check if (val1 = val2) as an assignment ... we overlooked it every time ... glad to hear you found the error ;)

kind regards
Dec 23 '07 #12
acoder
16,027 Recognized Expert Moderator MVP
I finally figured it out. It was ONE character. The line where the javasript sends the variables to the php portion had a '$' instead of '&' on one of them.
In your code in post #1, there's no $, but it must've accidentally been added by the time you got to post #7.
Prime example of why i'm not a coder :oP

Thanks for all your help :o) Much appreciated.
As gits said, it doesn't mean you're not a coder. Glad you got it working and good luck with your project.
Dec 23 '07 #13

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

Similar topics

3
14562
by: Jean-Philippe Encausse | last post by:
Hi, I got 2 bugs using AJAX with ISO-8859-1: 1. While serializing form's value using prototype.js I lost accent éàè ... because it use encodeURIComponent() function. I saw on google, for ISO-8859-1 encoding I have to use escape(). It works fine ! 2. While receving content from AJAX Request with header <?xml
6
401
by: Joel Byrd | last post by:
I want a website that works in the following way: It has a main content div, and of course menu items. When you click a menu item, it should use AJAX to change the main content div to the content of the page of the menu item you clicked. So, for example, if you clicked "About Us", then in the main content div, you would see the content of the about us page. Now, this is pretty simple if the content of a given page is just text (I just...
9
15076
by: Eric Wallstedt | last post by:
I have a page that "logs" changes made to input fields using ajax to pass data to a cgi. I use POST and it works fine most of the time (all the time in IE). But it fails when I get the data from a popup that invokes a function that in turn invokes ajax. Scenerio 1. user clicks a button to create a popup 2. the user selects a select member and clicks a button and a
1
16503
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX - microlink pattern tutorial : A microlink is a link that opens up
1
2185
by: jobo | last post by:
I have a news section of the website contained within the updatepanel. What I want is that when a news summary is clicked, the news item opens up in that same box. I thought I wired everything up correctly so that it did not do a postback. But when I walked through the execution process, it in fact does cause a postback when the "expand" event is raised. Why does this happen? Can someone help me? Thanks. Here is the .aspx part
0
3163
by: jrnail23 | last post by:
I have a user control which contains an UpdatePanel, which contains a MultiView inside, with a GridView in one of the views. In my GridView, I have a ButtonField which is supposed to trigger a server-side operation, using the RowCommand functionality. In IE, this all works great, but in Firefox (v2.0.0.6), clicking the above mentioned ButtonField fires off two similar AJAX requests, which is causing errors in my server-side code. ...
2
3164
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
3
3949
by: dhsieh | last post by:
I am trying out nested AJAX calls for the first time, but I seem to have hit a snag. The code snippet is the outer AJAX call and a function, it gathers information about a company. As we get towards the bottom of the onComplete function, there is a call to doGetAddressContacts(), which accepts an address ID. This then returns a list of contacts at that address. What I am trying to do is for each address that it retrieves and outputs, as it...
3
6879
by: ToddFur | last post by:
I see several postings on this but I am still unable to figure out my problem. I can pass the values of my text field but not radio button (or even checkboxes). My PHP file <?php //declare our variables $day = $_GET; $date = $_GET; $groupname = $_GET;
0
8674
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
9157
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...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7721
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...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
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
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
1999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.