Send data from jQuery to PHP for mailing -


i’ve javascript file i’ve been using template site i’m working on , in script there simple form validation – if no error occur – sends data php page called contact.php.

but i’m unsure on how “grab” data send javascript in php site? contact.php works – is, if i, in form, direct directly contact.php sends mail without problem. in file send variables this: $name = $_post['formname']; , on , in end send mail function.

the code in javascript file sends data , display “successful” message on same page is:

$.post("contact.php", { formfrom: fromvalue, formname: namevalue, formmessage: messagevalue }, function(data){ $("#loadingimage").fadeout("fast", function() {                 $("#loadingimage").before('<p>the message has been sucessfully send. thank you!</p>');       }); } ); 

the namevalue, messagevalue, fromvalue set in form validation var messagevalue = $("#formmessage").val();.

any appreciated.

sincere
- mestika

just use jquery ajax call (this syntax jquery 1.5.x):

$.ajax({     type: 'post'     url: urlstring,     data: {formfrom: fromvalue, formname: namevalue, formmessage: messagevalue} }).success(function(data, status, xhr) {     var obj = eval('(' + data + ')');     //response object }); 

to send json javascript, use function in php:

http://php.net/manual/en/function.json-encode.php

one other thing: rule of thumb, it's poor practice use variable names "fromvalue." initial capitalization supposed used class names, not variables (javascript developers borrowed practice java).


Comments

Popular posts from this blog

how to build hyperlink for query string in php -

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

queue - mq_receive: message too long -