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.
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.
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.
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.
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;
}