Submitting a form with ajax in Wordpress
Try something like this, you did not add the name
parameter you are expecting in your PHP contact_form
function, so you must add it to the data
attribute in the jQuery ajax function call.
$('#ajax-contact-form').submit(function(e){ var name = $("#name").val(); $.ajax({ data: {action: 'contact_form', name:name}, type: 'post', url: ajaxurl, success: function(data) { console.log(data); //should print out the name since you sent it along } });});