You can pass an ID to the form.
e.g. /my-page?ID=1223
The form can have a hidden field for the ID.
This code in functions.php can then change the email address:
// To determine which Councillor/Officer should receive the email.
add_filter( 'gform_notification_7', 'sws_change_destination_email', 10, 3 );
function sws_change_destination_email( $notification, $form, $entry ) {
$councillor_id = rgar( $entry, '12' );
$councillor_name = get_the_title($councillor_id);
$councillor_email = get_post_meta($councillor_id, 'wpcf-email', true);
// toType can be routing or email
//$notification['toType'] = 'email';
// change the "to" email address
//$notification['to'] = 'tim@sws-sb.co.uk';
$notification['to'] = $councillor_email;
//$notification['message'] .= "n --The Team @ rocketgenius - " . $councillor_name . ' - ' . $councillor_email ;
return $notification;
}
Notes:
- The filter name contains the ID of the form to target
- rgar needs the ID of the field to get