I have a javascript file serializing and sending a form to the php function:
function call_ajax(){
var data2 = jQuery('#newIdeaForm').serialize(); // <--- Important
jQuery.ajax({
type: 'POST',
url: myAjax.ajaxurl,
data: ({action : 'savedata',data : data2}),
success: function() {
alert(data2);
}
});
};
The thing is that I don't know how to receive this form in this php function:
function savedata(){
$my_post = array(
'post_title' => 'data.name',
'post_content' => 'data.idea',
'post_status' => 'publish',
'post_author' => $user_id,
);
wp_insert_post($my_post);
die();
}
Some fields of the form are 'name' and 'idea', I know the var data2 receive the form serialized but don't know how to get this form into the php funcition.
Other question: In the alert event of the javascript file it alerts the serialized form, how could I unserialize this form to alert just the name field?