New user registration – Forminator API – possible?
-
Hello!
Forminator_API::add_form_entry is only creating a form with given data from a webhook but what if I want to do is that run the process with a registration form. Is this possible? Because cforn_user_registered is not working.
Thanks:
Peter
-
And sorry – if possible, can I call forminator_resend_notification_email with an API call? because with add_form, the submission created but the email is not sent to the user.
Thank you!I tried 2 versions: POST and AJAX call, but forminator_resend_notification_email but nothing happening, email notification not sent – manually from submissions in wordpress admin it is working. Is there some special call? admin-ajax.php and admin-post.php not working for me with these codes after creating add_form_entry
Really thanks!
Peter
1. (AJAX)
https://pastebin.com/hS3upjia
2. (POST):
https://pastebin.com/25DfjiU8Hello @hollosipeter ,
I’ve reached out to our developers and they will take a look at your code and advise how to proceed.
We will keep you posted.
kind regards,
KasiaThank you Kasia!
PeterHello @hollosipeter ,
Can you try changing
$ajax_nonce = wp_create_nonce('ajax_nonce_action');
to$ajax_nonce = wp_create_nonce('forminatorResendNotificationEmail');
in this snippet https://pastebin.com/hS3upjiakind regards,
KasiaHello Kasia!
I tried, but when the form is creating by webhook/Forminator_API, no automatic e-mail notification sent – if I click manually after the submission, of course the email notification sent.
Thank you,
PeterThanks for response!
The “add_form_entry” method does only what it says – adds entry. It’s not meant to trigger e-mails as it’s an API method. It’s intended to be used to add data but nothing more, as usually in API use cases, you would want to address other tasks separately.
There is a method to send e-mails already available in a different class and you can use it. Here is a working modification of your codes:
$entry_id = Forminator_API::add_form_entry( $form_id, $entry_meta ); if ($entry_id) { $form = Forminator_API::get_form( $form_id ); $entry = Forminator_API::get_entry( $form_id, $entry_id ); (new Forminator_CForm_Front_Mail)->process_mail( $form, $entry, $entry_meta ); }
Note: form and entry are fetched in the code via API after entry is added because those methods return objects that the “process_mail” needs and in your code you only have bare data and form ID.
Anyway, this is tested and works, sending notifications as configured in form settings.
Kind regards,
AdamHello Adam!
Thank you for your answer.
I’m used wp_mail argument in the last few days – but it was very complicated to put every data to a $ variable, so it will be better if I can user forminator.
I tried to change now wp_.mail to your suggestion and making an API call (this is creating a user from a 3rd party system) but unfortunately no e-mail arrived to admin and to my test user (I am a rule in Forminator settings: if password field is not blank, then sending the mail, but I tried with and without filling this, turn offed the rule or turned on but no e-mail arrived.
Can you maybe check – this is my full code – the last few lines is the matter, I’m puting the same what you wrote:
https://pastebin.com/7y2bcvEh
Really thank you,
PeterHi @hollosipeter,
Could you please replace the following part of the code in your snippet:
if ($entry_id) { $form = Forminator_API::get_form( $form_id ); $entry = Forminator_API::get_entry( $form_id, $entry_id ); (new Forminator_CForm_Front_Mail)->process_mail( $form, $entry, $entry_meta ); }
With the following and see whether it helps:
if ( $entry_id ) { $form = Forminator_API::get_form( $form_id ); $entry = Forminator_API::get_entry( $form_id, $entry_id ); $submit_data = wpmudev_recreate_prepared_data( $entry, $form ); Forminator_Front_Action::$prepared_data = $submit_data; (new Forminator_CForm_Front_Mail)->process_mail( $form, $entry ); } function wpmudev_recreate_prepared_data( $entry, $form ) { $prepared_data = wp_list_pluck( $entry->meta_data, 'value' ); $fields = $form->get_real_fields(); foreach ( $prepared_data as $key => $value ) { if ( isset( $value['result'] ) ) { $prepared_data[ $key ] = $value['result']; } elseif ( is_array( $value ) ) { foreach ( $value as $subkey => $subvalue ) { $prepared_data[ $key . '-' . $subkey ] = $subvalue; } } elseif ( 0 === strpos( $key, 'select-' ) || 0 === strpos( $key, 'radio-' ) || 0 === strpos( $key, 'checkbox-' ) ) { foreach ( $fields as $field ) { if ( empty( $field->raw['element_id'] ) || $key !== $field->raw['element_id'] ) { continue; } if ( empty( $field->raw['options'] ) || ! is_array( $field->raw['options'] ) ) { break; } $field_labels = wp_list_pluck( $field->raw['options'], 'label' ); $field_values = wp_list_pluck( $field->raw['options'], 'value' ); $multiple_values = explode( ', ', $value ); $prepared_data[ $key ] = $multiple_values; foreach ( $multiple_values as $multiple_key => $multiple_value ) { $field_value_key = array_search( $multiple_value, $field_labels, true ); if ( false !== $field_value_key ) { // Replace saved field Labels to the relevant field values. $prepared_data[ $key ][ $multiple_key ] = $field_values[ $field_value_key ]; } } break; } } } $prepared_data['form_id'] = $entry->form_id; return $prepared_data; }
The above add snippet adds a custom function wpmudev_recreate_prepared_data which returns a data array containing form values.
Please check and let us know how that goes.
Kind Regards,
Nithin
Hello Nithin and thanks!
When I change to your code, I get back from the webhook:
“There has been a critical error on this website. Please check your site admin email inbox for instructions” / woo:l71lWcP+AgADTy2HW4bjSUnF
But submission is created and other things before forminator api – i mean db updates are worked, but error with the ajax call and the email not sent.
Should I change “form_id” or any tag in this script to my form id 23868?
Thank you,
PeterCritical error will return a log so we can know where the issue is located, can you please enable the debug mode https://wpmudev.com/blog/debugging-wordpress-how-to-use-wp_debug/ then replicate the issue but this time check the debug.log for the generated line?
Best Regards
Patrick FreitasHi Patrick!
Unfortunately no debug created and in the console I didn’t see anything – the ajax code not succeed. This is a webhook file.
This function,pmudev_recreate_prepared_data
-it overwrites the type and value of $prepared_data before reaching the end of the function. If the $value variable is empty, the value is overwritten at the beginning of the foreach loop. Is this okay?
And the other “kinda error”: in the foreach loop the identification and process elements with select-, radio-, or checkbox-: $key variable with $fields try to find an appropriate field, but if it is not found, uses ‘continue’ command to move on. But I have values came from a 3rd party system and not all my ‘values’ i named select-x radio-x, I have values like “fullname”, “birthdate”, etc. The array names fits to forminator: email-1, text-1, date-2, etc.
So can you check please the code – you have my full pastebin in this topic.
Thank you very much,
PeterHope you are doing fine.
In this specific scenario it is crucial to get info from the logs, in order to adjust the code that is causing the critical error. If the debug.log was not created, it is possible the following line is present in the wp-config.php file:
define( 'WP_DEBUG', false);
Could you help us verify this on your end? Then change it to :
define( 'WP_DEBUG', true);
If the line is not present, could you check if there is another error.log file accessible in the server? The hosting support team could provide further help with this.
Let us know if you gather more info from the logs in the suggested sources.
Kind regards
Luis
Hello Luis!
I have a php-errors.log because this is a do action ajax calling admin-post.php:
[13-Jun-2023 23:41:02 UTC] PHP Fatal error: Uncaught Error: Call to undefined function wpmudev_recreate_prepared_data() in /var/www/clients/client13/web108/web/wp-content/mu-plugins/forminator-webhook_automail.php:679
So error in the wpmudev_recreate_prepared_data function – as I assumed firstly.
Thank you,
PeterHi @hollosipeter,
The above error would point out that the wpmudev_recreate_prepared_data() isn’t defined anywhere.
Could we know how you are implementing the mentioned code? It is via a mu-plugin? Is there more code other than what you have shared in Pastebin?
Could you please share the final code with the suggested changes which you have tried via Pastebin, so that we could have a better idea regarding the issue noticed?
Looking forward to your response.
Kind Regards,
Nithin
- The topic ‘New user registration – Forminator API – possible?’ is closed to new replies.