Okay if I understand the setup so far correctly, the contact Form is placed in the Trainer template, and there is an email field in the Trainer post type that you want to use as the destination of the automatic email notification. To preserve the security of that email address and prevent spam, it's best not to include the email address directly in the form itself. Instead, I would use a generic hidden field to store the ID of the current Horse Trainer post, and determine the correct email address using our Forms API and bit of custom code.
In the Forms notification settings, you can choose any arbitrary email address for the notification destination, like "no-reply@yoursite.com". We will override that with the PHP API.
Add a generic hidden field and give it a slug like "trainer-id". You can set the default value of a generic hidden field using this shortcode:
[wpv-post-id item="$current_page"]
That will save the current Trainer post's ID in the hidden field, which we can then use in the email notification API.
add_filter('cred_notification_recipients', 'modify_trainer_recipients', 10, 4);
function modify_trainer_recipients($recipients, $notification, $form_id, $post_id) {
$forms = array(123);
$notification_name = 'Content submitted';
$trainer_email_field_slug = 'trainer-email';
$generic_field_slug = 'trainer-id';
// you should not edit below this line
// Check notification name matches target notification
if ( in_array($form_id, $forms) && isset($notification['name']) && $notification_name == $notification['name'] )
{
$trainer_email = get_post_meta( $_POST[$generic_field_slug], 'wpcf-'.$trainer_email_field_slug, true);
$recipients[] = array(
'to' => 'to',
'address' => $trainer_email,
'name' => '',
'lastname' => ''
);
}
return $recipients;
}
You would replace 123 with the numeric ID of the Contact Trainer form, replace Content submitted with the notification name, replace trainer-email with the slug of the email custom field from the Trainer post, and replace trainer-id with the slug of the generic field containing the trainer ID.
API documentation is available here:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients
Let me know if you have questions about this. I ran a quick test with a similar setup and saw the notification sent as expected.