Jump to content

landing page issues... couldn't make it run


roy_barak

Recommended Posts

I'm trying to build a landing page with php & js validation - i create the html/php & etc, but the .JS script always hangs on the last "else"... and gives the "123" alert... i debugged it for syntax problem for hundred of time with any online debugging site i know - but it's seems to be something else.... 

 

 

 


_______________JS / AJAX_________________

  



$(document).ready(function(){

 

$('form.landing-form').submit(function(){

 

var name = $.trim($('input[type=text].field-name').val());

var email = $.trim($('input[type=text].field-email').val());

var phone = $.trim($('input[type=text].field-phone').val());

 

var nameReg = /^[a-zA-Z ]+$/;

var emailReg = /^([\w-\.]+@([[\w-]+\.)+[\w-]{2,4})?$/;

var phoneReg = /^[0-9-+]+$/;

 

$('input[type=text]').removeClass('error');

 

if(name.length < 2 || !nameReg.test(name)){

 

$('input[type=text].field-name').addClass('error');

$('input[type=text].field-name').val('');

$('input[type=text].field-name').attr('placeholder','*valid name is requierd!');

} else if (email.length < 5 || !emailReg.test(email)) {

 

$('input[type=text].field-email').addClass('error');

$('input[type=text].field-email').val('');

$('input[type=text].field-email').attr('placeholder','*email is requierd!');

 

}  else if (phone.length < 9 || !phoneReg.test(phone)) {

 

$('input[type=text].field-phone').addClass('error');

$('input[type=text].field-phone').val('');

$('input[type=text].field-phone').attr('placeholder','*phone is requierd!');

 

} else { 

$.ajax({

   url: "handler/form_handler.php",

   type : "POST",

   dataType: "html",  

   async: "false",  

   data : { name:name, email:email, phone:phone },

   beforeSend : function () {

var messege = '<img src="images/ajax-loader.gif" border="0">';

messege += '  Sending...';

$('form.landing-form label').html(messege);

 

},

success: function(response) {

if(response == 'true'){

 

alert('321');

 

} else {

 

 

alert('123');

 

     }

 }

});

}

return false;

 

});

});

 

 

_______________PHP_________________


 


<?php

 

echo 'hi';

die();

   

$name = filter_var($_POST['name'],FILTER_SANITIZE_STRING);

$email = filter_var($_POST['email'],FILTER_VALIDATE_EMAIL);

$email = filter_var($email,FILTER_SANITIZE_EMAIL);

$phone = filter_var($_POST['phone'],FILTER_SANITIZE_STRING);

 

if (empty ($name)|| empty ($email) || empty ($phone)) {

 

 

return;

}else{

 

mysql_connect('localhost' , 'root' , '');

mysql_select_db('show_express');

 

 

$name = clean_inputs ($name);

$email = clean_inputs ($email);

$phone = clean_inputs ($phone);

 

$sql = "INSERT INTO clients(id,name,email,phone) ";

    $sql .= "VALUES('','$name','$email','$phone')";

    mysql_query($sql);

 

if (mysql_affected_rows()) {

echo true;

 

}

 

 

}

   function clean_input($input) {

   $clean = mysql_real_escape_string(stripcslashes($input));

   return $clean;

   

   }

   

  // function sendMail ($name,$email,$phone){

  // $from = $email;

///$messege = 'name:' . $name .',';

//$messege .= 'email:' . $email .',';

//$messege .= 'phone:' . $phone .',';

//mail ("[email protected]" , "clients info from landing page", $messege, "from: $from\n");

 

 

 

 

 

 

 //  }

   

?>


 

here is my code , 


Link to comment
https://forums.phpfreaks.com/topic/289760-landing-page-issues-couldnt-make-it-run/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.