Problem:
A Form includes a generic field, and the form notifications should be sent depending on the value of this generic field. How is that possible?
Solution:
The solution involves the use of the Toolset Forms API and some custom code.
Specifically, two hooks are used, cred_notification_event_type and cred_custom_notification_event_type_condition.
The first registers a custom type of event (distinct from the standard event types such as on submit), and the second performs some logic for the custom event and returns true or false depending on whether the notification should be sent or not.
Here is some boilerplate code that needs expanding to include such logic:
function tssupp_custom_notification($notification_type, $notification, $form_id, $post_id) { if ( // Target the form and its notification $form_id == 39 && $notification['name'] == 'Thing published' ) { // Define a custom notification type $notification_type = 'maybe_notify'; } return $notification_type; } add_filter('cred_notification_event_type', 'tssupp_custom_notification', 99, 4); function tssupp_custom_notification_condition($condition_status, $notification, $form_id, $post_id) { if ( // Target the form and notification and the notification type $form_id == 39 && $notification['name'] == 'Thing published' && $notification['event']['type'] == 'maybe_notify' ) { // Perform whatever tests you want and return true (send notification) or false (don't) $condition_status = true; } return $condition_status; } add_filter('cred_custom_notification_event_type_condition', 'tssupp_custom_notification_condition', 99, 4);
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_event_type
https://toolset.com/documentation/programmer-reference/cred-api/#cred_custom_notification_event_type_condition
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
This topic contains 12 replies, has 3 voices.
Last updated by 6 years, 1 month ago.
Assisted by: Nigel.