Skip Navigation

[Resolved] Form notification to an email field of the page which contains the form

This support ticket is created 3 years, 11 months 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

Author
Posts
#1939831

Tell us what you are trying to do?
I'm trying to add a notification to an email address of one of my custom field

I'm working on a website similar to a real estate example.
The owner can add a lot of structures and fill a lot of fields. One of these fields is the email of the structure's owner.

I create a relationship between Messages and structures and on each structure page, I published a form for users who want to ask for some information about the structure.

I need
1 ) the email shows the name of the structure.
2) the form is sent to the email of the structure's owner.

1) Post name issue: I tried to use %%POST_TITLE%% [wpv-post-title output="sanitize"] [wpv-post-title] but I see CRED Auto Draft 48ac6a82a1595204666869437f1cec6f

2) Notification issue: I add this code to the toolset custom code page.

function modify_recipients($recipients, $notification, $form_id, $post_id) {
// Check notification name matches target notification
if ( isset($notification['name']) && 'owner-notification' == $notification['name'] ) {
// Add email recipient
$parent_id = toolset_get_parent_post_by_type( $post_id, 'struttura' );
//$parent_id = toolset_get_related_post( $post_id,'struttura-messaggio');
$email_of_owner = get_post_meta($parent_id, 'e-mail-struttura', true);
$recipients[] = array(
'to' => 'cc',
'address' => $email_of_owner,
'name' => '',
'lastname' => ''
);
}
return $recipients;
}

As you can see I tried both 'toolset_get_parent_post_by_type' and 'toolset_get_related_post' but notification isn't sent.

What is wrong with my code? Could you help me, please?
Thank you so much.

Is there any documentation that you are following?
yes https://toolset.com/forums/topic/cred-notification-to-email-from-parent-post-field-no-longer-working-after-types-3-0-update/

Is there a similar example that we can see?
yes

What is the link to your site?
hidden link

#1940427

Hi,

Thank you for contacting us and I'd be happy to assist.

To troubleshoot this on a test website, I'll need to see exactly how the related elements are set up on your website.

Can you please share temporary admin login details in reply to this message?

Note: Your next reply will be private and though no changes will be made, please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1942389

Thank you for sharing these details.

I noticed that the form "Modulo per Messaggi" is being used on the single "Strutture" posts, but this form doesn't have any field to specify which "Strutture" post the newly created "Messaggi" should be linked to.

As a result, you'll see that a number of recent "Messaggi" posts have no "Strutture" post attached to them.

To fix this, you can add a "Strutture Messaggi" field in that form and for the default field value use the "[wpv-post-id]" shortcode, so that the current "Strutture" post is automatically selected, when the form loads.
( screenshot: hidden link )

Once the relationship connection is properly made with the post created using this form, you can check your code snippet for the recipient with the "toolset_get_related_post" function.

#1951231
3.png
2.png
1.png

Hi Waqar,
I did what you suggested but it still doesn't work.

I'm sending you my setting so you can check them and help me to find the issue.

This is the code I'm using:

add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);

function modify_recipients($recipients, $notification, $form_id, $post_id) {
// Check notification name matches target notification
if ( isset($notification['name']) && 'owner-notification' == $notification['name'] ) {
// Add email recipient
$struttura = toolset_get_related_post( $post_id, array( 'struttura', 'messaggio' ) );
$email_of_owner = get_post_meta($struttura, 'e-mail-struttura', true);
$recipients[] = array(
'to' => 'to',
'address' => $email_of_owner,
'name' => '',
'lastname' => ''
);
}
return $recipients;
}

I receive the post title as CRED Auto Draft 48ac6a82a15952046....... with any field type I try to use.
And I don't receive any notification.

Thanks.

#1955775

Hi Anna,

Thank you for waiting while I performed some tests on my website with a similar setup.

I was able to make this work, using the "toolset_get_related_posts" function:
( ref: https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts )


add_filter('cred_notification_recipients', 'modify_recipients', 10, 4);
function modify_recipients($recipients, $notification, $form_id, $post_id) {
	// Check notification name matches target notification
	if ( isset($notification['name']) && 'owner-notification' == $notification['name'] ) {
		$get_results = toolset_get_related_posts(
							$post_id,
							'struttura-messaggio-owner',
							'child',
							1000,
							0,
							array(),
							'post_id',
							'parent'
						);

		$email_of_owner = get_post_meta($get_results[0], 'wpcf-e-mail-struttura', true);
		
		$recipients[] = array(
							'to' => 'to',
							'address' => $email_of_owner,
							'name' => '',
							'lastname' => ''
							);
	}
	return $recipients;
}

regards,
Waqar

#1955933

My issue is resolved now. Thank you!

#1968407
Screenshot 2021-02-26 at 19.17.51.png

Hi, I'm sorry but I was wrong.
Email notification doesn't arrive to the owner but to the user who sends the request.
I have checked the wrong email addresses.

Are notification settings correct? Or should I set one e-mail recipient?

Thank you for your help.

Best.