Skip Navigation

[Resolved] Send Notification From Email in Parent CPT

This support ticket is created 6 years, 6 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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 3 voices.

Last updated by Luo Yang 6 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#891893

Hi,

I have a CPT that shows Bar Listings and I’d like to have a form on each listing page that allows visitors to contact the Bar (custom email field in the cpt). I created a child cpt “Contact a Bar” and created a CRED form that creates news “Contact a Bar” cpt .

You can see an example of this form here on the right sidebar:
hidden link

I can't seem to retrieve the email from the parent cpt. This is the generic email field I'm using:

[cred_generic_field field="_wpcf_email-address" type="email" class="" urlparam=""]
{
"required":0,
"validate_format":0,
"persist":1,
"default":"[[types field='email-address' id='$directory-listing'][/types]"
}
[/cred_generic_field]

This should work right?

Tim

#892295

There is a solution, but it's a tricky one.

1. The $directory-listing, which get's its ID from the current Post (it's supposed parent) does not return the "To be created" post ID, but the ID of the page/post where you insert the Form.

This is expected, as at this time, no Post ID (no post object) is created at all, hence it can only fall back to the current page/post.

2. Therefore you would need to get the Parent Post ID from the Toolset Forms URL parameter that sets the parent:

parent_{parent-post-type-slug}_id

This could then be called in a ShortCode using the Views "Search Parameter" ShortCode:

[types field="email" id="[wpv-search-term param='parent_{parent-post-type-slug}_id']" output='raw'][/types]

But this will fail because there are more than 2 layers of nested apostrophes, hence you cannot alternate single and double apostrophes anymore and WordPress itself will destroy the ShortCode before it's output.

3. Natively in Toolset Forms, you can display these parent data:

[cred-post-parent get='id']
[cred-post-parent get='title']
[cred-post-parent get='url']

https://toolset.com/documentation/user-guides/cred-forms-for-child-content/#information-about-parent-items

Again you cannot use this, to populate the ID of a Field ShortCode, since it has apostrophes on it's own.

However that I made this work with this code:

[cred_generic_field field='email_here' type='email' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[types field='email' output='raw' id='[wpv-search-term param="parent_toolset-post-type_id"]'][/types]"
}
[/cred_generic_field]

But, remember that the apostrophes are tricky.

#894848

Thanks Beda, this works. With the nested apostrophes do you mean that this may break in the future?

And just one more thing. I have the form set to "display a message instead of the form" and " AJAX submission" but the page is reloading and no message is being shown. You can see what I mean if you fill out the Contact form on this Test Listing:

hidden link

Tim

#895031

Q1) With the nested apostrophes do you mean that this may break in the future?
No, it will work in the future, shortcode in shortcode is a built-in feature of Toolset, see our document:
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/

Q2) page is reloading and no message is being shown
It is abnormal, in case it is a compatibility problem, please try this:
1) deactivate other plugins and switch to wordpress default theme, and test again
2) Enable PHP debug mode, copy and paste the debug logs here
PHP Debugging
In case you think that Types or Views are doing something wrong (what we call a bug), you should enable PHP error logging. Again, edit your wp-config.php file and add the following:

ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
This will produce a file called ‘error_log.txt’ in your WordPress root directory. Make sure that the web server can create and write this file. If it cannot, use an FTP program to create the file and make it writable to Apache (normally, user www-data).
https://toolset.com/documentation/user-guides/debugging-types-and-views/
3) If the problem still persists, please provide a database dump file (ZIP file) of your website in below private detail box, also point out the problem page URL, I need to test and debug it in my localhost, thanks