Skip Navigation

[Resolved] Sequence of CRED form API hooks?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 8 replies, has 3 voices.

Last updated by himanshuS 1 month ago.

Assigned support staff: Jamal.

Author
Posts
#2171553

I want to know when is the email notification sent during saving a CRED form.

I want to take an action AFTER the email is sent with custom field data. So I need to know which hook can I use to do that. Is there a hook at fires after notifications are sent?

#2171667

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

The last available Forms API hook is cred_success_redirect (https://toolset.com/documentation/programmer-reference/cred-api/#cred_success_redirect), which is available assuming your form is set to redirect to the post or some page after submission.

Form notifications will have been enqueued by then, but the actual process of sending is tied to WP shutting down, and there isn't a hook available after the notifications have actually been sent.

Sending is via the core function wp_mail, and I checked the source code for that, and it doesn't provide an action after the messages have been sent either.

#2171677

Does enqueued notification mean that even if I change the custom field in the post, the information would have been captured?

Or does it mean that I cannot change the custom filed with redirect hook without changing the message in the notification.

#2171885

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

The email will be written before being sent. If you have changed the data between the moment where the email has been enqueued, and the moment it is being sent, the email will contain the last data to be saved.

Keep in mind that you will still have the submitted data in the global $_POST array. If you need that data, you can access it using custom placeholders. Check this article https://toolset.com/documentation/programmer-reference/forms/how-to-use-custom-placeholders-in-cred-notifications/

#2172219

I still do not understand the full sequence. Thank you for your patience. Let me try one more time -

1) I want to edit a post with a form with custom fields including a message field.
2) Use data submitted in the form to send an email. The email would also contain the message field.
3) When the email is sent, I want to delete the data in the message field of the post. This way, the user receives the message via email notification.
4) Now when the author decides to edit the post again, they don't see the previous message and can send a new message on submitting the form.

Can this be done in the toolset with the message field data being deleted after the email is sent with the message data? If yes, how?

#2172777

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I don't see why would you save this message on the database if you intend to delete it just after. Why not use a generic field(which won't be saved in the database at all), and create your own placeholder, for the notification, to get the content of that generic field. Check an example here https://toolset.com/forums/topic/include-custom-generic-fields-added-to-the-form-in-the-notification-email/

If you still want to execute some logic when the form is submitted, register your own handler to the shutdown action. https://developer.wordpress.org/reference/hooks/shutdown/

You may want to register the handler when the form process has been completed successfully https://toolset.com/documentation/programmer-reference/cred-api/#cred_submit_complete

#2172811

Jamal,

The generic field would solve the problem for me. Thank you.

#2172835

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Awesome, I am glad I could help. I'll set this ticket as maybe resolved. If you don't need further assistance, please mark it as resolved.

#2172847

My issue is resolved now. Thank you!