I have a jquery function that takes form values, serializes them and passes them to a php function in a Wordpress plugin. When I try to retrieve the post values, I can only retrieve the entire string, not each value. Here is my current jquery function:
jQuery('.lesson_complete').change(function () {
if (jQuery(this).is(":checked")) {
//var module = jQuery(this).parent().find('.module-id').val();
//alert(module);
var progress_post = jQuery(this).parent().serialize();
jQuery.ajax({
type: "POST",
url: submitprogress.ajaxurl,
data: {
action: 'submit_progress',
data: progress_post
},
success: function (response) {
//alert(form_parent);
//alert('success');
alert(progress_post);
alert("working" + response);
//jQuery("#feedback").html(data);
}
});
return false;
}
})
<form type="post" action="#" id="moduleProgressForm">
<label for="lesson_complete">Finished with this lesson?</label>
<input type="checkbox" class="lesson_complete" value="1" name="lesson_complete" />
<input type="hidden" name="user_id" value="'.get_current_user_id().'"/>
<input type="hidden" name="post_id" value="'.$current_post.'"/>
<input type="hidden" class="module-id" name="module_id" value=""/>
</form>
I can access the string using this in the function:
$post_values = $_POST['data']
It returns this string:
lesson_complete=1&user_id=2&post_id=1&module_id=1
But I can't access individual post values. What am I doing wrong?