Hi @phloo,
Trust you are doing good and thank you for reaching out to this.
You can configure the email routing to send based on some conditions. If you want to send this email to different recipients conditionally, you can enable the email routing and change the recipients of this email based on the user input. For example, you can add a hidden field and set the default value as Page title or Page ID. Then you can add an email routing with a condition to trigger only when a condition is met (like the hidden field is a particular page title or ID)
Please find an example of a hidden field: https://ibb.co/kSrzPY7
Reference for email routing: https://ibb.co/ZTmQGJh
Please find more about conditions with email notification in our documentation here: https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#email-notifications-forms
I hope that helps.
Kind Regards,
Nebu John
Thread Starter
phloo
(@phloo)
hi @wpmudevsupport14
thanks, but this is not what I asked for. I know about email routing.
As I tried to explain: the email addresses come from a custom field from the post/page itself.
It is NOT set in the form itself.
We want to use 1 global contact form and add the recipient address dynamically.
Hello there @phloo
You can achieve this with a little bit of custom coding.
First, add a Hidden field to your form, select a Custom Value for it and use “custom_email”.
View post on imgur.com
Now we will need to replace this default value with the value of the custom field of your pages. Let’s say that your custom field has label “your_custom_email”, then you will need the following filter:
<?php
add_filter( 'forminator_field_hidden_field_value', function( $value ){
if( $value === 'custom_email' ){
$post_id = get_queried_object_id();
$custom_email = get_post_meta( $post_id, 'your_custom_email', true );
$value = $custom_email;
}
return $value;
} );
You can use this in a MU plugin file, ref: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
Finally, use the Hidden field value as the actual email recipient:
View post on imgur.com
Warm regards,
Dimitris
Thread Starter
phloo
(@phloo)
Hi Dimitris / @wpmudev-support6
thanks for this guide. Helps a lot.
I was researching for more solutions and found this:
add_filter( 'forminator_custom_form_mail_admin_recipients',
function( $recipients, $custom_form, $data, $entry ){
$check_field = 'select-1';
$emails = array(
'emailone' => array(
'david.hansen@lpl.com'
),
'emailtwo' => array(
'tanya.mathews@lpl.com'
),
'emailthree' => array(
'richard.mower@lpl.com'
),
'emailfour' => array(
'richard.weintraub@lpl.com'
),
'emailfive' => array(
'lexy.schmidt@lpl.com'
),
'emailsix' => array(
'mdedoyo@bradcable.com'
),
);
$check_value = $data[ $check_field ];
if ( isset( $emails[ $check_value ] ) ) {
return $emails[ $check_value ];
}
return $recipients;
},
20, 4 );
With a little tweaking it will probably work the way without revealing the mail addresses in the html source code.
Thanks again
Hi @phloo
I hope you are doing well
Thank you for the information, I would suggest editing the code removing the emails as it is a public thread.
I am marking this case as resolved, but feel free to ping us any time you need.
Best Regards
Patrick Freitas