Skip Navigation

[Resolved] Need help with CRED form notification

This thread is resolved. Here is a description of the problem and solution.

This support ticket is created 2 years, 5 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: Africa/Casablanca (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by nicoleR-3 2 years, 5 months ago.

Assisted by: Jamal.

Author
Posts
#2191225

Tell us what you are trying to do?
I have a contact form that I am inserting in a page and I would like to use either the parent post title or a custom field from the parent post for the confirmation message and the notification email sent to the client.

In my example, the form is inserted on a page of a horse that is for sale. What I would like to happen is that when the form gets sent to the client, the horse's name is automatically added to the subject and in the message area, as well as being added to the message confirmation to the user on the website. So, it would say something to the effect: "You have received an inquiry about Cisco Kid".

I have tried a couple different things, but it has not worked, no horse name is being inserted anywhere.

Is there any documentation that you are following?
Searched online and couldn't find anything that exactly addressed my issue.

Is there a similar example that we can see?

What is the link to your site?
The page where the form is inserted is here: hidden link

#2192179

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Hello and thank you for contacting Toolset support.

Well, the notification emails can use placeholders such as %%POST_TITLE%%. Apart from that, you must pass the ID in the item attribute of the shortcodes. For example to get a custom field "video" from the current post, you can use the following shortcode:

[types field="video" item="%%POST_ID%%" ][/types]

To get information of the parent post, you must use the item attribute and pass the relationship slug, something like:

[types field="video" item="@relationship-slug.parent" ][/types]

Read more about the item attribute here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

As we must pass the post ID in the item attribute, we can't really pass the relationship slug. So, we need to go through a content template. Create a content template, and add the field from the parent post like:

Title: [wpv-post-title item="@relationship-slug.parent"]
Video: [types field="video" item="@relationship-slug.parent" ][/types]

Then use the content template inside the notification and pass the post ID to it:

[wpv-post-body view_template="name or slug of the content template" item="%%POST_ID%%"]

I hope this helps. Let me know if you have any questions.

#2192205

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

I forgot to mention, that you can also create a placeholder that will return the parent post title or a custom field, using the relationship API. Check these articles:
- https://toolset.com/documentation/programmer-reference/forms/how-to-use-custom-placeholders-in-cred-notifications/
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post

#2192289

Hi Jamal,

I tried your instructions in the first email and none of them worked. Confirmation and notification are still returning no value regardless of what I'm adding.

I would have tried the second suggestion, but it wasn't clear to me where I am supposed to add the code for the generic field.

#2192705

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Would you allow me temporary access to your website to check this further? Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

About adding custom code, please check this article:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/

#2194055

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

Well, you have to update the relationship slug in the shortcode. The used relationship slug is "horse-sale-horse-inquiry". Use this:

[wpv-post-title item="@horse-sale-horse-inquiry.parent"]

Instead of:

[wpv-post-title item="@relationship-slug.parent"]

But, because the content template is generated with some additional CSS code. Which makes it a little bit complicated. We'll need to use custom code to clean the return value.

Because this needs custom code, I opted to create placeholders and use them on the notification directly. So, I added the following code to Toolset->Settings->Custom code:

add_filter('cred_body_notification_codes', 'custom_generic_field_notification');
add_filter('cred_subject_notification_codes', 'custom_generic_field_notification');
  
function custom_generic_field_notification( $defaultPlaceHolders ) {
  $parent_id = $_REQUEST['@horse-sale-horse-inquiry.parent'];
  $newPlaceHolders = array(
    '%%FIXED_PARENT_TITLE%%' => get_the_title($parent_id),
    '%%FIXED_PARENT_LINK%%' => get_permalink($parent_id)
  );
  
  return array_merge($defaultPlaceHolders, $newPlaceHolders );
}

Then I used the placeholders %%FIXED_PARENT_TITLE%% and %%FIXED_PARENT_LINK%% directly in the notification subject and body. It gave the expected results. Check this screenshot hidden link

I hope this helps. Let me know if you have any questions.

#2194355

Thank you so much for this! One more question. I want to do this same thing with another CRED form on the website for Events on the News page (hidden link). When the form is filled out, I want to auto populate it with the title of the event so the client knows which event the user is messaging about.

How would I add or adapt the code that you created above for a second function?

#2196969

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+00:00)

The easiest way would be to add two different placeholders for this relationship too. The relationship slug is "event-event-inquiry", so, the following code should work:

$parent_id = $_REQUEST['@horse-sale-horse-inquiry.parent'];
  $newPlaceHolders = array(
    '%%FIXED_PARENT_TITLE%%' => get_the_title($parent_id),
    '%%FIXED_PARENT_LINK%%' => get_permalink($parent_id)
  );

$event_id = $_REQUEST['@event-event-inquiry.parent'];
  $newPlaceHolders = array(
    '%%FIXED_EVENT_TITLE%%' => get_the_title($parent_id),
    '%%FIXED_EVENT_LINK%%' => get_permalink($parent_id)
  );
   
  return array_merge($defaultPlaceHolders, $newPlaceHolders );

Notice that the placeholders for the enquiry are '%%FIXED_EVENT_TITLE%%' and '%%FIXED_EVENT_LINK%%' instead of '%%FIXED_PARENT_TITLE%%' and '%%FIXED_PARENT_LINK%%'

#2197177

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.