The function wp_insert_post()
returns the post ID on success or the value 0 on error.
Your PHP function should look like this :
function save_enquiry_form_action() {
$args = [
// Your postdata...
];
$is_post_inserted = wp_insert_post($args);
if( !empty($is_post_inserted) ) {
wp_send_json_success([
'post_id' => $is_post_inserted,
'post_title' => get_the_title( $is_post_inserted ),
]);
} else {
wp_send_json_error();
}
}
Finally, in the Ajax return we get the information to send to the popup.
<script>
$.ajax({
[...] // everything before success function was good.
success: function(response) {
if ( response.success == true ) {
// in case of `wp_send_json_success()`
var post_id = response.data.post_id;
var post_title = response.data.post_title;
$('#tvesModal .modal-content p').html(post_id + "<span>" + post_title + "</span>");
modal.style.display = "block";
body.style.position = "static";
body.style.height = "100%";
body.style.overflow = "hidden";
} else {
// in case of `wp_send_json_error()`
alert("Insert Failed");
}
}
});
</script>