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
    Aug 2011
    Posts
    52
    Thanks
    24
    Thanked 0 Times in 0 Posts

    Help with syntax errors

    i get this error when ever i try to process the form:

    There was a SyntaxError: Unexpected token < error due to an parsererror condition.


    Javacsipt/jquery:

    $(document).ready(function(){

    $("#slide").click(function(){
    $("#inner-wrapper").slideToggle();
    });

    $('form #response').hide();
    $('#submit').click(function(e){

    e.preventDefault();

    var valid = '';
    var required = ' is required';
    var name = $('form #name').val();
    var email = $('form #email').val();
    var fname = $('form #fname').val();
    var femail = $('form #femail').val();
    var message = $('form #message').val();
    var honeypot = $('form #honeypot').val();
    var humancheck = $('form #humancheck').val();

    //Error checking


    if (name == '' || name.length <=2) {
    valid = '<p>Your name' + required + '</p>';
    }

    if (!email.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/)) {
    valid += '<p>Your email' + required + '</p>';
    }

    if (fname == '' || fname.length <=2) {
    valid += '<p>Your friend\'s name' + required + '</p>';
    }

    if (!femail.match(/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/)) {
    valid += '<p>Your friend\'s email' + required + '</p>';
    }


    if (message == '' || message.length <=5) {
    valid += '<p>A message' + required + '</p>';
    }

    if (honeypot != 'http://') {
    valid += '<p><center>Spambots are not allowed.</center></p>';
    }

    if (humancheck != '') {
    valid += '<p><center>A human user' + required + '</center></p>';
    }

    if (valid != '') {
    $('form #response').removeClass().addClass('error')
    .html('<strong>Please correct the errors below.</strong>' + valid).fadeIn('2000');
    }else {
    $('form #response').removeClass().addClass('processing').html('<center>Working...</center>').fadeIn('2000');

    var formData = $('form').serialize();
    submitForm(formData);

    }

    });

    });

    function submitForm(formData) {
    $.ajax({
    type: 'POST',
    url: 'emailfriend.php',
    data: formData,
    dataType: 'json',
    cache: false,
    timeout: 7000,
    success: function(data) {
    $('form #response').removeClass().addClass((data.error === true) ? 'error' : 'success')
    .html(data.msg).fadeIn('fast');

    if ($('form #response').hasClass('success')) {
    setTimeout("$('form #response').fadeOut('slow')", 5000);
    }
    },

    error: function(XMLHttpRequest, textStatus, errorThrown) {
    $('form #response').removeClass().addClass('error')
    .html('<p>There was a <strong>' + errorThrown +
    '</strong> error due to an <strong>' + textStatus +
    '</strong> condition.</p>').fadeIn('fast');
    },
    complete: function(XMLHttpRequest, status) {
    $('form')[0].reset();
    }

    });
    };

    php file

    PHP Code:
    <?php
      error_reporting
    (E_ALL E_NOTICE);
      
      
    sleep(3);
      
      
    $name stripslashes($_POST[name]);
      
    $email stripslashes($_POST[email]);
      
    $fname stripslashes($_POST[fname]);
      
    $femail stripslashes($_POST[femail]);
      
    $message stripslashes($_POST[message]);
      
    $honeypot $_POST[honeypot];
      
    $humancheck $_POST[humancheck];
      
      if (
    $honeypot == 'http://' && empty($humancheck)) {
      
          
    $error_msg '';
          
    $reg_exp "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/";
          
          if (!
    preg_match($reg_exp$email)) {
             
    $error_msg .= "<p>A valid email is required</p>"
          }
          
            if (!
    preg_match($reg_exp$femail)) {
             
    $error_msg .= "<p>A valid email is required</p>"
          }
          
          if (empty(
    $name)) {
             
    $error_msg .= "<p/>Please provide your name</p>";
          }
          
          if (empty(
    $fname)) {
             
    $error_msg .= "<p/>Please provide your name</p>";
          }
          
          if (empty(
    $message)) {
              
    $error_msg .= "<p>A message is required.</p>";
          }
          
          if (!empty(
    $error_msg)) {
             
    $return['error'] = true;
             
    $return['msg'] = "<h3>Oops! Looks like you missed a few fields.</h3>".$error_msg;
             echo 
    json_encode($return);
             exit();
             
          }else {
            
    $return['error'] = false;
          
            
    $ref=@$HTTP_REFERER
            
    /////Message at the top of the page showing the url////
            
    $header_message "Hi $fname \n Your friend $name requested you to visit this page at \n $ref \n";
            
    /// Body message prepared with the message entered by the user ////
            
    $body_message =$header_message."\n".$message."\n";
            
    // IP address of visitor is added to message, you can remove it if not required.//
            
    $body_message .="\n Sent from http://www.separatethescams.com";
            
    //// Mail posting part starts here /////////

            
    $headers="";
            
    //$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers; 
             // Un comment the above line to send mail in html format
            
    $headers4=$email;         // Change this to change from address
            
    $headers.="Reply-to: $headers4\n";
            
    $headers .= "From: $headers4\n"
            
    $headers .= "Errors-to: $headers4\n"

            
    $subject="$name visit this site!";

            
    mail($femail,$subject,$body_message,$headers);
          
             
    $return['msg'] = " <b><p><center>Thanks for spreading the word! :) " "<font color='red'>" .$name .  "</font>" " </p>" "</b>" "</center>";
             echo 
    json_encode($return);
          }
          
      }else {
          
    $return['error'] = true;
          
    $return['msg'] = "<h3><center>0ops there was a problem submitting the data. Please try again!</center></h3>";
          echo 
    json_encode($return);
      }

    ?>

    html file

    <html>
    <head>
    <link rel="stylesheet" href="ajaxform/form.css" type="text/css" media="screen"/>
    </head>
    <body>

    <div id="wrapper">
    <h3 id="slide">Email This Page To a Friend</h3>
    <hr></hr>
    <div id="inner-wrapper">

    <form id="my_form" action="ajaxform/emailfriend.php" method="post">

    <div id="response"><!--This will hold error message and response from server. --></div>
    <div class="inputs">
    <p>
    <label>Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;</label>
    <input name="name" type="text" placeholder="Your Name" class="required" id="name" size="30" />
    </p>
    </div>

    <div class="inputs">
    <p>
    <label>Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;</label>
    <input name="email" type="text" placeholder="Your Email" class="required" id="email" size="30" />
    </p>
    </div>

    <div class="inputs">
    <p>
    <label>Friend's Name&nbsp;&nbsp;</label>
    <input name="fname" type="text" placeholder="Friend's Name" class="required" id="fname" size="30" />
    </p>
    </div>

    <div class="inputs">
    <p>
    <label>Friend's Email&nbsp;&nbsp;</label>
    <input name="femail" type="text" placeholder="Friend's Email" class="required" id="femail" size="30" />
    </p>
    </div>

    <div class="inputs">
    <p>
    <label id="msg">Message&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <textarea name="message" cols="24" rows="5"type="text" placeholder="Message To Friend" class="required" id="message"></textarea>
    </p>
    </div>

    <div class="button">
    <input name="submit" type="submit" id="submit" value="EMAIL PAGE" />
    </div>

    <div class="inputs">
    <input type="hidden" name="honeypot" id="honeypot" value="http://" />
    <input type="hidden" name="humancheck" id="humancheck" class="clear" value="" />
    </div>

    </form>
    </div> <!-- inner-wrapper end -->
    </div>

    <script type="text/javascript" src=" https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="ajaxform/ajax_submit.js"></script>
    </body>
    </html>

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,338
    Thanks
    13
    Thanked 348 Times in 344 Posts
    and on which line do you get that error?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    LinkBacks (?)


    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
    •