Question

Link: http://thrivingkings.com/read/Formly-The-form-glamorizer-for-jQuery

I am making a contact form using Formly and I was wondering how you actually send the message to your server/ to an email address.

Their example is:

<script>
$(document).ready(function() { 

$('#ContactInfo').formly({'theme':'Dark'}, function(e) { 

    $('.callback').html(e); 
});
});
</script>

and they say:

This time, we setup a callback function which will give us the data in URL format. This is not the safest method of transferring user data and should not be used with secure information. Also, you can easily change the callback method to .serializeArray() to receive the data in JSON.

How do you you recieve data in JSON? I understand what they are saying by using .serializeArray() but I don't know how to send that data. I don't have much experience with this.

Thanks.

Was it helpful?

Solution

You'd send the data to your server by utalizing jQuery POST like this:

var postData = $("#ContactInfo").serializeArray();
$.post('ajax/test.html', postData, function(returnData) {
    console.log(returnData);
}, "json");

From http://api.jquery.com/jQuery.post/

Put the path to your server endpoint, that handles the posted data in replacement of ajax/test.html.

I did assume #ContactInfo is your form element.

I did use $.serializeArray() to create a sendable JSON of your form content, as you can see here http://api.jquery.com/serializeArray/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top