roy_barak Posted July 11, 2014 Share Posted July 11, 2014 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 ("barakroy@gmail.com" , "clients info from landing page", $messege, "from: $from\n"); // } ?> here is my code , https://www.dropbox.com/s/d5i6r32ag5tgewt/Landing%20Page.rar Quote Link to comment https://forums.phpfreaks.com/topic/289760-landing-page-issues-couldnt-make-it-run/ Share on other sites More sharing options...
ginerjm Posted July 12, 2014 Share Posted July 12, 2014 1 - you didn't post your code with tags as per the rules. 2 - you appear to be saying this is a JS problem. How about posting (with tags) in the JS forum instead? Quote Link to comment https://forums.phpfreaks.com/topic/289760-landing-page-issues-couldnt-make-it-run/#findComment-1484750 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.