Skip Navigation

[Resolved] send email notification on form update

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Author
Posts
#1174165

Tell us what you are trying to do?
Send an email notification to an email address not displayed in the post update form (it is not displayed for security reasons). It is stored as custom field in the post in back end - not visible on front end post update form.

Is there any documentation that you are following?
I checked here: https://toolset.com/documentation/programmer-reference/cred-api/#cfv

Is there a similar example that we can see?
no

What is the link to your site?
hidden link

#1174182

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - as you acknowledge that you have hidden custom field that holds the email and you want to send the email to that hidden custom email field. If this is correct?

What if you try to use the Toolset Forms hook: cred_notification_recipients

For example:

add_filter('cred_notification_recipients', 'func_custom_send_notification', 10, 4);
function func_custom_send_notification($recipients, $notification, $form_id, $post_id) {
  
  // Check notification name matches target notification
      if($form_id == 123){ //replace it with your CRED form ID
          // Add a BCC to log@emailaddress.com
        $recipients[] = array(
            'to'        =>  'bcc',
            'address'   => 'log@emailaddress.com',
            'name'      =>  '',
            'lastname'  =>  ''
            );
    }
    return $recipients;
}

Where:
- Adjust the values as needed with above code and replace the address key value with your hidden email field.

More info:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients

#1174194

Hi Manesh,

Thanks for the response!

The email is not hidden in the form.

The email is stored as a variable in a custom field in any post record (post_id) being updated, but we don't want to add that field/value to the front end update form. The reason is because the email is sensitive private information that we do not want exposed to the public or hackers.

When a user submits the form, we want a function that queries the database for the email address variable that is stored in a certain custom field within that post_id record.

We can not hard-code the email address. It needs to be dynamic, as each post_id has a unique email address in the custom field.

We then want to send an email notification to that email address that has been found.

I hope this is more clear.

Please let me know.

Thanks!

#1174199

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes, its clear. To guide you in the right direction, I need problem URL where I can see the form as well as the email field name that holds the email value.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1175099

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thank you for sharing all required details.

I've added the following code to Toolset's custom code section - where we are fetching the "primary_contact_email" value and send the notification to the stored database value of field "primary_contact_email".

add_filter('cred_notification_recipients', 'func_custom_send_notification', 10, 4);
function func_custom_send_notification($recipients, $notification, $form_id, $post_id) {
   
  // Check notification name matches target notification
      if($form_id == 8167){ //replace it with your CRED form ID
        
        // gettting primary contact email
        $primary_email = get_post_meta($post_id ,'wpcf-primary_contact_email',true);
        
        // add notification to primary email
        $recipients[] = array(
            'to'        =>  'to',
            'address'   => $primary_email,
            'name'      =>  '',
            'lastname'  =>  ''
            );
    }
    return $recipients;
}

More info:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients