Hi @pstidsen
I hope you’re fine today!
Simplest way to get it would be to use different hook. Here is a working example:
add_action( 'forminator_custom_form_submit_before_set_fields', 'forminator_custom_get_entry_id', 20, 3 );
function forminator_custom_get_entry_id( $entry, $form_id, $field_data_array ) {
$submission_id = $entry->entry_id;
error_log( "SUBMISSION ID:" . $submission_id );
}
Best regards,
Adam
Hi Adam
Thanks for your reply.
I want to use the submisison ID to redirect the user to a custom page. It does not seem to be possible to redirect the user during that hook.
Best Regards,
Peter
Hi @pstidsen,
I want to use the submisison ID to redirect the user to a custom page.
You want to redirect the submission/entry ID as a URL parameter to the custom page?
If yes, maybe you can refer the following custom snippet which redirects in similar workflow:
https://gist.github.com/wpmudev-sls/619d8140953daac80094abadad0ef66f
Please check and see whether it fits your requirement.
Kind Regards,
Nithin
Hi there,
Actually the submisison ID has to be an input to a function that the generate a payment link which the user should be redirected to. I have that helps clarifying.
I have made everything else – I just need the submission ID (so that submission and payment can be compared later on).
Best Regards,
Peter
-
This reply was modified 1 year, 1 month ago by
pstidsen.
Hi @pstidsen,
In that case, in the initial code that you have shared, you could try adding this code:
$entry = forminator_get_latest_entry_by_form_id( $form_id );
$entry_id = $entry->entry_id;
For example:
add_action('forminator_form_after_save_entry', 'wpmudev_form_submit_success_check', 9999, 2);
add_action('forminator_form_after_handle_submit', 'wpmudev_form_submit_success_check', 9999, 2);
function wpmudev_form_submit_success_check($form_id, $response){
if ($response && is_array($response)){
if ($response['success']){
$entry = forminator_get_latest_entry_by_form_id( $form_id );
$entry_id = $entry->entry_id;
}
}
}
Could you please check and see whether that helps?
Best Regards,
Nithin
Hi Nithin,
Wouldn’t that, at least theoretically, mean that the IDs could be mixed up if the form is submitted multiple times at the same time.
Best Regards,
Peter
Hi @pstidsen
You can try a bit different approach based on the code I share earlier:
1. first, get the ID and save it:
add_action( 'forminator_custom_form_submit_before_set_fields', 'forminator_custom_get_entry_id', 20, 3 );
function forminator_custom_get_entry_id( $entry, $form_id, $field_data_array ) {
$_POST['_forminator_cform_entry_id'] = $entry->entry_id;
}
2. and then in other hook that allows redirect (like your initial code) you simply read it like
$entry_id = $_POST['_forminator_cform_entry_id']
This mixes both approaches but would made sure that ID’s are not messed up (with Nithin’s approach is very unlikely too but not impossible; here you got 100% certainty) and yet it can be used in other hook to redirect.
Best regards,
Adam
Hi Adam,
Awesome! That’s a perfect solution !
Have a nice weekend 🙂
Best Regards,
Peter