• Resolved sinned1

    (@sinned1)


    Hi there, I’m trying to do my own way to handle the POST method for the Form Submit, and I’m trying to disable/remove the action/function that makes the default way, I have found the script and read it just to understand it, I also found the “wp_ajax_forminator_submit_form_’ . static::$entry_type, array( $this, ‘save_entry’ )“, which in my case I asume is the same as“wp_ajax_forminator_submit_form_custom-forms, array(‘Forminator_Front_Action’, ‘save_entry’)
    And knowing this I have tried to do a remove_action() on my functions.php so I can make my handler, but it doesn’t work. Is this even possible somehow? or is there a way that I can’t see
    Thanks in advance, I will appreciate every help:)


    Kind regards,

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @sinned1

    I hope you are doing well.

    Forminator will do different background checks in the background for example sanitising the fields, removing the post means not only the entry save is removed but also all the safety.

    Can you describe further what you are trying to do, for example, save the form entry in a different table / database or any different reason for handling it on your own?

    I ask because some filters can help to hook the existing functions instead of removing them.

    Best Regards
    Patrick Freitas

    Thread Starter sinned1

    (@sinned1)

    Hi! sorry for the late response, and yeah I realize that once I read the JS code for the submit, but I only want to try to replace this with my own is like a task I need to do. Even with that if it’s possible to do it like this I would like to know how, or if there is a way to create another JS function that executes parallel to the original one, so both trigger when submit it works for me too. Thanks in advance!

    Thread Starter sinned1

    (@sinned1)

    Now that I think, is there maybe a way to just copy the exact same code as “front.submit.js” to another script, there just add the actions I want to do with the data that POST take to handle but doing it this way so I don’t lose every kind of check that the original does. But I still don’t have a clear idea of how can I remove the default one and make this new one with “front.submit.js” in. I understand that the js that is executed is the “front.multi.min.js” so that is what I want to remove somehow, thanks in advance for any help!

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @sinned1

    Thank you for response!

    I’m afraid that’s not really an option. All the submission process is much more complex than this. By entirely removing its own submission you’d most likely essentially turn the plugin to a basic form HTML markup builder, not really much different than just creating form manually (or using free online builder) in HTML.

    I’m pretty sure though that you have some specific reason for attempting this and “just changing POST handling” is not the main one. Are you trying to skip or change some sort of validation or make form send data to some external/custom URLs/endpoints or, in general, do something specific (that Forminator doesn’t do out of the box) with submitted data?

    I’m asking this because knowing that could help us suggest an actual solution that would work better with Forminator and wouldn’t require “hacking” (so to speak) the plugin basic functionality…

    Kind regards,
    Adam

    Thread Starter sinned1

    (@sinned1)

    Hi there again! Yes so, basically I just want to keep the default AJAX actions but I want to be able to use the data sent on POST for other purposes at the moment submit action is triggered, to make it short and clear if there is a way to add to the already existing AJAX some actions (simple example: adding text to a <p> element with some of the POST data) on success would be enough for me to try some things that I want. I already found some filters/actions that has the data that is give by the POST but even if that could work it is not specifically what I want to try, I know my request can be ambiguous but that’s basically it.
    Thanks if there is some kind of idea!

    • This reply was modified 6 months ago by sinned1.
    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @sinned1

    Okay then, thanks for explanation. I think hooking up to existing filters may be a better idea here but just one additional question (to make sure we are on the same side here).

    You wrote: “to be able to use the data sent on POST for other purposes” and then “(simple example: adding text to a <p> element with some of the POST data)“.

    So do you want to take the data submitted in the form and e.g. save it to some custom tables or send to external API (or similar) or do you actually want to modify the submitted data at the moment between after form is submitted but before it’s saved to DB/send in e-mail?

    Or both?

    Best regards,
    Adam

    Thread Starter sinned1

    (@sinned1)

    Hi, thanks for the quick response!
    And actually right now I don’t want to do none of the things you said, maybe later up with my project but at the moment, I just want to be able to do actions on the ajax success action e.g having an empty div available to put inside this the data retrieved from the POST just to show it to the user as a summary, I know this is doable with the default submission behaviour on Form creation, but this is just to try this kind of functionality with this basic example and then maybe trying more things later, but now it’s just to test it.
    Thanks again!

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    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

    Thread Starter sinned1

    (@sinned1)

    Hi again, this works just fine, exactly how I wanted.
    Thanks for every response and the final solution, even though it was kind of an ambiguous request.
    Have a great day, kind regards!

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.