Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2009
    Location
    Tampa, Florida. US
    Posts
    18
    Thanks
    5
    Thanked 1 Time in 1 Post

    Question Jquery, Ajax submit form, get response... :(

    Hello,

    I am trying to AJAX a typical contact form on this website... (http://marcosrobles.com/contact.php)

    When I fill out the form and click "Send" I get the success message added to the page, but there was no response from the PHP file, and the email is not sent

    I am new to AJAX, so I am not sure why this doesn't work. I expect to see the "Thanks for contacting me." as a "response" (in firebug console.) upon success.

    I can see the POST call, I can see what was posted, and It looks correct, except for the missing response.

    Ajax call
    Code:
        $(".general-submit").click(function(){
    var general_fname = $("#general_fname").val();
    var general_lname = $("#general_lname").val();
    var general_email = $("#general_email").val();
    var general_phone = $("#general_phone").val();
    var general_phone2 = $("#general_phone2").val();
    var general_phone3 = $("#general_phone3").val();
    var general_message = $("#general_message").val();
    
    var data_msg = "general_fname="+general_fname+"&general_lname="+general_lname+"&general_email="+general_email+"&general_phone="+general_phone+"&general_phone2="+general_phone2+"&general_phone3="+general_phone3+"&general_message="+general_message;
       
        $.ajax({
       type: "POST",
       url: "/includes/validate-general.php",
       data: data_msg,
       success: function(){
    $('#general-tab').html("<div class='messages success-general'></div>"); 
    $('.messages').html("<h3>Contact Form Submitted!</h3>")
       .append("<p>We will be in touch soon.</p>");
       }
    });
    return false;
    
    });
    PHP
    Code:
    <?php
    $errmsg =  '';
    $general_fname = '';
    $general_lname = '';
    $general_email = '';
    $general_phone = '';
    $general_phone2 = '';
    $general_phone3 = '';
    $general_message = '';
    
    function isEmail($email) {
        return preg_match('|^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$|i', $email);
    };
    
    
    
    if(isset($_POST['general-submit']))
    {
       $general_fname = $_POST['general_fname'];
       $general_lname = $_POST['general_lname'];
       $general_email = $_POST['general_email'];
       $general_phone = $_POST['general_phone'];
       $general_phone2 = $_POST['general_phone2'];
       $general_phone3 = $_POST['general_phone3'];
       $general_message = $_POST['general_message'];
       
       if(trim($general_fname) == '')
       {
          $errmsg = '<p class="errorMsg">Please enter your first name</p>';
       }
       if(trim($general_lname) == '')
       {
            $errmsg .= '<p class="errorMsg">Please enter your last name</p>';
       }
       if(trim($general_email) == '')
       {
          $errmsg .= '<p class="errorMsg">Please enter your email address</p>';
       }
       if(!isEmail($general_email))
       {
          $errmsg .= '<p class="errorMsg">Please enter a valid email address.</p>';
       }
       if(trim($general_message) == '')
       {
          $errmsg .= '<p class="errorMsg">Please enter your message</p>';
       }
    
    if($errmsg == '')
    {
       if(get_magic_quotes_gpc())
       {
          $general_message = stripslashes($general_message);
       }
    
       $to      = "blue@ourownchange.com";
       $subject = '[General Information] : Inquiry from ' . $general_fname . ' ' . $general_lname;
       $msg     = "From :" . $general_fname . ' ' . $general_lname . "\r\n " . "Phone Number: " . "(" . $general_phone . ")-" . $general_phone2 . "-" . $general_phone3 . "\r\n" . "Message: " . $general_message;
       mail($to,
            $subject,
            $msg,
            "From:" . $general_email. "\r\nReturn-Path:". $general_email."\r\n");
    
            echo "Thanks for contacting me.";
       } else{ echo $errmsg;}
       }
    Please help.


    EDIT: AHA moment! basically, the PHP was searching to see if the submit value was posted before it would run... I didn;t have the AJAX xubmit that value.... works now!
    Last edited by blue642; 04-27-2010 at 06:02 PM. Reason: resolved issue.

  • #2
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I'm getting the same issue, but unable to fix it. Mind to share how did you ensure ajax submit the value to make it work.

    Thank you


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •