jQuery, AJAX, and PHP post from front end
-
I have a form that passes field values to jQuery, which validates the fields and creates the variables being sent in
data: {}
in the snippet below.$.ajax({ type: "POST", url: "<?php bloginfo('stylesheet_directory'); ?>/process.php", dataType: "json", data: { "title":title, "goals":goals, "progress":progress, "categories":categories, "tags":tags, "video":video, "audio":audio, }, success: function() { //get permalink for post from php and go to it } }); process.php is not receiving any data, or it's not posting the data. I'm not sure why. Here is process.php <?php $user_submitted_title = sanitize_text_field($_POST['user_submitted_title']); $user_submitted_progress = $_POST['user_submitted_progress']; $user_submitted_goals = $_POST['user_submitted_goals']; $user_submitted_categories = $_POST['user_submitted_categories']; $user_submitted_tags = sanitize_text_field($_POST['user_submitted_tags']); $user_submitted_video = sanitize_text_field($_POST['user_submitted_video']); $user_submitted_audio = sanitize_text_field($_POST['user_submitted_audio']); $user_post = array( 'comment_status' => 'open', 'post_author' => $user_ID, 'post_category' => array($user_submitted_categories), 'post_content' => '<h2>Project Progress</h2>' . $user_submitted_progress . '<h2>Project Goals</h2>' . $user_submitted_goals, 'post_status' => 'publish', 'post_title' => $user_submitted_title, 'post_type' => 'post', 'tags_input' => $user_submitted_tags ); $user_post_id = wp_insert_post($user_post); add_post_meta($user_post_id, 'wpcf-video', $user_submitted_video); add_post_meta($user_post_id, 'wpcf-audio', $user_submitted_audio); $user_post_redirect = get_permalink($user_post_id); ?>
I need to figure out why nothing posts when I use the form, and I need to figure out how to send $user_post_redirect back to jquery so I can redirect to it. Can someone please help?
- The topic ‘jQuery, AJAX, and PHP post from front end’ is closed to new replies.