Hi @marashmallow
Hope you are doing fine.
If you need to add an unique identifier to a submission, you can use some custom code. When a submission id is added in a hidden field, the value is not available in the webhook as you have experienced already.
There is a code snippet that generates a unique id for a submission and you can use it instead of the submission_id value. You can use the unique id to associate the redirected user. The code can be found in this link:
https://gist.github.com/wpmudev-sls/e3e4655e9ad74686051393a1d0ed5ffa
Please add the code as a must-use plugin to your site’s wp-content/mu-plugins folder. Please find more instructions here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins.
The following code line has to be replaced with the form id (instead of 100) and the hidden field (if different from ‘hidden-1’) where you need the unique identifier to be generated.
100 => 'hidden-1',
We recommend to test this on the dev/staging version first before putting it on the live site.
Hope it will solve your problem. Let us know if you have additional questions or concerns.
Kind regards
Luis
Thanks for your response. Unfortunately, there are several problems with the code you referred me to:
1. Since PHP 8, the function signature on line 148 must be changed from
public function wpmudev_is_unique( $num = '', $form_id, $form_field ) {
to
public function wpmudev_is_unique( $form_id, $form_field, $num = '' ) {
and accordingly also the function call on line 185.
2. The code stops a redirect from occurring.
3. A webhook call occurs but it doesn’t transfer the value of the hidden field. The value is still just the literal “submission_id”. This happens despite the fact that I can see a random string being entered into the database for the hidden field.
-
This reply was modified 2 years, 11 months ago by
marashmallow.
Hi @marashmallow,
Thanks for the follow up, I have passed your feedback regarding PHP 8 to get it sorted in the snippet asap.
In the meanwhile, could you please check and see whether the following snippet helps?
<?php
add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_add_submission_id_hidden', 10, 3 );
function wpmudev_add_submission_id_hidden( $entry, $module_id, $field_data_array ) {
if ( $module_id != 6 ) {
return;
}
foreach( $field_data_array as $key => $value ) {
if ( $value['name'] == 'hidden-1' ) {
Forminator_CForm_Front_Action::$prepared_data['hidden-1'] = $entry->entry_id;
}
}
}
You’ll have to update the above code with your form ID in the following line:
if ( $module_id != 6 ) {
Suppose the form ID is 123 the above line will change to:
if ( $module_id != 123 ) {
The code can be added as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
Best Regards,
Nithin
Hello @marashmallow ,
We haven’t heard from you for over a week now, so it looks like you no longer need our assistance.
Feel free to re-open this topic if needed.
Kind regards
Kasia