Skip Navigation

[Resolved] Post form not connecting to parent cpt after submitting

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

This topic contains 9 replies, has 2 voices.

Last updated by J_MG9702 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2449745

Tell us what you are trying to do?
My directory/membership site registers users with woocommerce subscriptions, then the user can create their cpt "Coordinator" profile, they can edit it, etc. All this works fine so far. The problem is on the Coordinator landing page there is a post form for a new cpt "TC Contacts" this will allow a guest to submit a message and the site will save it in the backend under TC Contacts and will send a notification to the admin and the email set by the "Coordinator" profile from the landing page a guest submitted the form from. Ideally the form would gather this relationship info from the back and do it all hidden. I originally had the form working where after it was submitted it connected the TC Contact message to the Coordinator in the cpt backend (so it was linked for admin usage) and it also sent the email to the email listed on the parent Coordinator profile. I had to configure the user registration flow since we are using subscriptions and now I can't get it to work again. Any help in the right direction would be appreciated. Thank you!

Is there any documentation that you are following?
I have used all the documentation from the site as well as tried work arounds from the errata threads.

Is there a similar example that we can see?
Please send private message and I will add access.

What is the link to your site?
In development

#2450797

Hello,

I assume we are talking about this case:
1) Two post types:
- Coordinator
- TC Contacts

2) One post type relationship:
One-to-many relationship between "Coordinator" and "TC Contacts"

You are going to do these:
When guest create a new "TC Contacts" post using Toolset post form, send an email to the "Coordinator" post author

Where do you setup the "Coordinator" post email? is it a custom email field created with Toolset Types plugin? or the "Coordinator" post author user email?

Please elaborate the questions with more details, I have enabled the private message box, you can provide a test site with the same problem, also point out the problem page URL and form URL. thanks

#2452129

Thanks for the details, I can login into your website.

I assume we are talking about the post form "Submit your Listing".

1) Where can I edit your custom PHP codes?
2) Where and how can I test above post form in frontend?

I need to test and debug your PHP codes, thanks

#2452441
Screen Shot 2022-09-07 at 10.59.25 AM.png

Hi Luo,

The post form in question is TC Contact Form. I have attached a picture of it from the front end of a listing.

You can go to this listing landing page: [siteurl]/coordinator/jane-demo/

You can submit that contact form and you will see from the backend that it does not currently connect to the Coordinator landing page it is on "Jane Demo" in this case. And it does not send an email to the contact email custom field for the "Jane Demo" coordinator. Not the user email for the user that creates the "Jane Demo" listing.

The TC theme is a child theme where you can edit the custom php codes. I make adjustments in the WordPress theme editor.

Hope that clarifies your questions. Thank you!

#2455945

Thanks for the details, in your case, you don't need custom PHP codes, you just need to put the relationship field into the post form.
For example, edit the post form:
hidden link
add the relationship field "Coordinators TC Contacts", and setup the default value as:
[wpv-post-id item="$current_page"]

Then use CSS codes to hide above field, see our document:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/

#2456503
Screen Shot 2022-09-13 at 10.53.39 AM.png
Screen Shot 2022-09-13 at 10.12.42 AM.png

Hi Luo,

I guess that "works" but it does not solve my issue. When someone submits the TC Contacts form from the front-end the TC Contacts post is saved in the database, but it is not actually linking the Coordinator to the TC Contact. It is not making that relationship from the form being submitted. You can see after testing the form that it is not connected via relationship on the TC Contact post or the Coordinator's post in the back-end. I have attached a screenshot of what I am referring too.

Also, the TC Contacts form is not sending a notification email to the Coordinator it is in a relationship with. That is also an issue I am facing. See screenshot where I have attempted this already. Along the lines of the link you shared.

I previously tried the solution you provided after finding that in the documentation, but it does not solve my specific issue.

Thank you.

#2456813
Coordinators-TC-Contacts.jpg

As I mentioned above, you don't need those custom PHP codes, I have done below modifications in your website:
1) Edit your theme file "functions.php":
hidden link
comment out line 45~53

2) Test it in frontend:
hidden link
Fill and submit the post form,
I can see the new child item correctly:
hidden link
see my screenshot Coordinators TC Contacts.JPG

Can you confirm it? thanks

#2457521
Screen Shot 2022-09-14 at 2.08.02 PM.png

Hi Luo,

I can confirm that when someone submits the TC Contact post form the relationship between that cpt and the Coordinator cpt is happening. Thank you so much for helping me get that working correctly!!

There was also the matter of the email notification for the TC Contact post form not sending to the related Coordinator in question. I have tried both attributes: "$current_page" and "@{coordinator-tc-contact}.parent". Neither is sending to the email connected. For that same demo coordinator we have been testing with, the email field is set to my email so it should go to me once working. Maybe I am not thinking the flow of hierarchy correctly to get to the right attribute.

Thank you for your support on this!

#2457787
email-logs.jpg

The "Send notification to a specific email address" option does not support shortcode, in your case, you can try with Form API filter "cred_notification_recipients".

I have setup a demo in your website with below steps:
1) Install the Post SMTP plugin, with it you can trace the email logs

2) Edit the post form
hidden link
in email item "TC Contact Form Notification", option "Send notification to a specific email address", remove the shortcodes you mentioned above, change the value to your email address.

3) Edit theme file "functions.php", add lines 55~74:

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']) && 'TC Contact Form Notification' == $notification['name'] ) {
		// Parent coordinator post
		$coordinator_id = toolset_get_related_post( $post_id, 'coordinator-tc-contact' );
		$coordinator_email = get_post_meta( $coordinator_id, 'wpcf-contact-email', true );
		
        // Add a BCC to $coordinator_email
        $recipients[] = array(
            'to'        =>  'bcc',
            'address'   => $coordinator_email,
            'name'      =>  '',
            'lastname'  =>  ''
            );
    }
         
    return $recipients;
}

Test it in frontend:
hidden link
Fill and submit the post form,

Check the email logs, it works fine, see my screenshot email-logs.jpg
hidden link

#2458565

Hi Luo,

The email is now sending as required and everything is working! Appreciate all the support through this!