Hello @sinned1
Thank you for the further explanation. From what I understand, you are trying to manipulate the DOM after the Forminator response. You can get the entry items from formData and then handle the AJAX request, below is an example snippet that you can try to see if that helps, of course, this is just an example snippet that you can modify to suit your tests.
<?php
add_action('wp_footer', 'wpmudev_sample_of_code', 9999);
function wpmudev_sample_of_code()
{
global $post;
if (is_a($post, 'WP_Post') && !has_shortcode($post->post_content, 'forminator_form')) {
return;
}
?>
<script type="text/javascript">
jQuery(function($) {
$(document).on('forminator:form:submit:success', function(formData) {
var form_id = $(formData.target).attr('data-form-id');
// handle the ajax here
$.ajax({
url: '<?php echo admin_url('admin-ajax.php'); ?>',
type: 'POST',
data: {
action: 'my_custom_ajax_function_from_form',
formId: form_id,
},
success: function(response) {
console.log(response);
},
error: function(error) {
console.log(error);
}
});
});
});
</script>
<?php
}
// register the Ajax action
add_action('wp_ajax_nopriv_my_custom_ajax_function_from_form', 'my_custom_form_submit_request');
add_action('wp_ajax_my_custom_ajax_function_from_form', 'my_custom_form_submit_request');
function my_custom_form_submit_request()
{
$form_id = isset($_POST['formId']) ? sanitize_text_field($_POST['formId']) : false;
$entry = forminator_get_latest_entry_by_form_id($form_id);
if (!$entry) {
wp_send_json_error(array(
'message' => 'No entry found',
));
}
// return a response
wp_send_json_success(array(
'message' => 'Form data received',
'form_id' => $form_id,
'entry' => $entry,
));
}
Here you can bring the entry data, or anything from PHP. Or in case you don’t want anything from PHP you can remove the $.ajax({ part within the snippet.
Here is how the response looks https://monosnap.com/file/2MuT9JpaZfDj2oiXtz1o687358NIT9
Hope this helps.
Kind Regards,
Saurabh