jQuery/ajax form - send to php problem -


i have nice looking slideup/slidedown jquery form on website. sends data same file send email. works fine:

$(document).ready(function(){     $('div.contact a.submit').click(function() {         var name = $('div.contact input.name').val();         var email = $('div.contact input.email').val();         var message = $('div.contact textarea.message').val();         $('div.contact').slideup('slow', function() {             $.ajax({                 type: "post",                 url: "test.php",                 data: "name=" + name + "&email=" + email + "&message=" + message,                 success: function(msg)                 {                     $('div.contact').html('<h1>contact</h1><div class="comment">success!</div><div class="clear"></div><p class="indent">thank you, in contact shortly.</p>');                     $('div.contact').slidedown('slow');                 }//end of success             });//end of ajax         });     }); }); 

the php @ top of test.php send email:

include("expander-b1.0.php"); $name = $_post['name']; $email = $_post['email']; $message = $_post['message']; sendmail("admin@site.co.uk", $message, "contact message $name", $email); 

this getting simple mail function external file. however, way validate form entry (including email validation), display error(s) in contact dive. not experienced jquery or ajax unable working using if statements in php , echoing variables in "success" part of ajax.

$(document).ready(function(){     $('div.contact a.submit').click(function() {         var name = $('div.contact input.name').val();         var email = $('div.contact input.email').val();         var message = $('div.contact textarea.message').val();          //email validation         var reg = /^([a-za-z0-9_\-\.])+\@([a-za-z0-9_\-\.])+\.([a-za-z]{2,4})$/;         if(reg.test(email) == false) {             alert('invalid email address');             return false;         }         //name , message validation         //-------- goes here ------------//          $('div.contact').slideup('slow', function() {             $.ajax({                 type: "post",                 url: "test.php",                 data: "name=" + name + "&email=" + email + "&message=" + message,                 success: function(msg)                 {                     $('div.contact').html('<h1>contact</h1><div class="comment">success!</div><div class="clear"></div><p class="indent">thank you, in contact shortly.</p>');                     $('div.contact').slidedown('slow');                 }//end of success             });//end of ajax         });     }); }); 

Comments

Popular posts from this blog

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -

openssl - Load PKCS#8 binary key into Ruby -