Is there any way to automate adding params into jQuery $.get ?
For the moment I’m listing those by hand – but what would I do if the form has 100s of fields?
Please see my comment in the code belowe.
$.get:
// How to automate this?
var ContactName = $('#contact-name').val();
var ContactEmail = $('#contact-email').val();
var ContactPhone = $('#contact-phone').val();
var ContactMessage = $('#contact-message').val();
$.get("contact-form.php", {
// How to automate this?
ContactName: ContactName,
ContactEmail: ContactEmail,
ContactPhone: ContactPhone,
ContactMessage: ContactMessage
}, function() {}).success(function() {
// Do stuff once email send
})
Simply use $(“#myForm”).serialize().
see http://api.jquery.com/serialize/
you can also use serializeArray() if you want to manually add some parameters to the serialized form, see http://api.jquery.com/serializeArray/