Hi @applecarrot
I hope you are doing well.
It seems a normal behaviour, but I suggest you use this hook instead:
forminator_form_after_handle_submit
<?php
add_action( 'forminator_form_after_handle_submit', 'my_callback_function', 20, 2 );
function my_callback_function( $form_id, $response ) {
if( $response['success'] ){
// example how to get the field
$name = $_POST['name-1'];
// Handle rest of code here
}
}
Let us know if this worked for you.
Best Regards
Patrick Freitas
Hi @wpmudevsupport12,
thank you for your quick answer, I’m astonished about how dedicated the WPMU support is.
I tried your suggestion but it didn’t work for two reasons:
1. it seems like the hook forminator_form_after_handle_submit
is only called when AJAX submit is deactivated? Non-AJAX would be very bad for UX, because all form fields are cleared every time a server side validation fails.
2. the hook is called even if validations fail and nothing is saved.
I want to send the form entry to the external API only when the form is fully validated and saved. Is there a way to do that?
Thank you & best regards,
Marie-Christine
Hi @applecarrot,
In that case, you could try using the filter forminator_form_after_save_entry
or forminator_form_after_handle_submit
and see whether it helps to cover both your queries.
Please do let us know how that goes.
Kind Regards,
Nithin
Hello Nithin @wpmudevsupport11,
thank you for your answer. Those are the two filters I already tried. Any other options?
Kind regards,
Marie-Christine
Hi @applecarrot
Thanks for response!
Why not do it straight from your own custom validation function “forminator_submit_form_validate_iban”?
You can check content of $submit_errors right above the
return $submit_errors;
line and if there’s no errors, you can call the other part of your code that submits data to external API.
You can take all the submitted data from $data variable that you have already available there (the very same way as you are using it to read IBAN from it for validation).
Best regards,
Adam
Hello @applecarrot ,
We haven’t heard from you for a while now, so it looks like you don’t have more questions for us.
Feel free to re-open this ticket if needed.
Kind regards
Kasia
Hi Adam @wpmudev-support8,
it would be difficult to call the code from the IBAN validation because there are several validators and I don’t know the order in which they are called.
I already have a workaround that involves comparing the submission timestamp to the current time. I was just looking for a “clean” solution, like a hook that only gets called when a new entry was saved. It seemed like a common use case. If a hook like this doesn’t exist, it’s okay, the workaround will do.
Regards & thank you all for your time,
Marie-Christine
Hi @applecarrot,
You could also check whether the following filter helps or not:
forminator_custom_form_submit_errors
You can use the above filter to implement custom validation, ie use the third filter param to get the current input.
For example:
self::$submit_errors = apply_filters( 'forminator_custom_form_submit_errors', self::$submit_errors, self::$module_id, self::$info['field_data_array'] );
However, the above will only help if you are looking for input values. If you are looking for an entry ID then the above filter won’t help too.
I have escalated this further to our developer’s attention to check the observation you have mentioned regarding the existing hooks and the limitation you are facing to see if there are any further improvements that are required or not within the plugin side or not.
Will keep you posted once we have further updates.
Kind Regards,
Nithin
Hi @applecarrot,
Could you please check and see whether implementing the code as follows helps to cover your needs:
add_action( 'forminator_form_after_save_entry', 'my_form_submit', 10, 2 );
function my_form_submit( $form_id, $response ) {
if ( $response && is_array( $response ) ) {
if ( $response['success'] ) {
if ( $form_id == THE_FORM_ID ) {
$entry = Forminator_Form_Entry_Model::get_latest_entry_by_form_id( $form_id );
}
}
}
}
I hope this helps in moving forward.
Kind Regards,
Nithin
Dear Nithin @wpmudevsupport11,
Yes, that solved it! Thank you!!
Wow, this is the third time the Forminator team helped me out. I already gave you a 5 star rating, so I’ll see if I can add a few German translations as a thank you.
Best Regards,
Marie-Christine