Skip Navigation

[Resolved] Correct way to use relationship form

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

Problem:

I have 3 CPT's that are all connected to each other, either a 1-1 or a 1-M relationship.

I would like to accomplish creating 1 form where it will have all the fields from all 3 CPT's, and they go can through all the options and then hit submit at the end. Is this possible?

Solution:

There isn't such kind of built-in feature within Toolset Forms plugin, one post form can handle only one post, you might consider custom codes, for example:

https://toolset.com/forums/topic/correct-way-to-use-relationship-form/#post-2240289

Relevant Documentation:

https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 3 years 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 4 replies, has 2 voices.

Last updated by simchaH 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2240009

Hi,

I am trying to figure out the best way to do set up my forms- I would like guest visitors to be able to go to a page and upload info via the form.

I have 3 CPT's that are all connected to each other, either a 1-1 or a 1-M relationship. I would like to accomplish creating 1 form where it will have all the fields from all 3 CPT's, and they go can through all the options and then hit submit at the end. Is this possible? I see there are 2 options, one for regular forms and one for a relationship form. Is the relationship form a way to connect all 3 CPT's into 1 form for users to submit?

If not, is there any other way to accomplish my goal? I am also okay with it being 3 separate forms developmentally, and just being able to display it on the frontend as 1 long one, if that is possible.

Also, is it the same form where someone will submit for a new listing/post as one would for updating a current post? Or is that a completely different form.

Thanks!

#2240289

Hello,

There isn't such kind of built-in feature within Toolset Forms plugin, one post form can handle only one post, you might consider custom codes, for example:
1) After user submit the post form, use action hook "cred_save_data" to trigger a custom PHP function:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

2) In this PHP function:
Create other two posts:
https://developer.wordpress.org/reference/functions/wp_insert_post/
And update post fields of above new two posts of other post types:
https://developer.wordpress.org/reference/functions/update_post_meta/
And related them with Types relationship API function:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/

For the question:
Also, is it the same form where someone will submit for a new listing/post as one would for updating a current post? Or is that a completely different form.
It is not a good idea to let guest user to create/edit posts, you don't know which guest is the post author.
In my opinion, users need to login into your website first, then create/edit their own posts, and connect those posts, see our documents:
https://toolset.com/course-lesson/front-end-forms-for-adding-content/
https://toolset.com/course-lesson/front-end-forms-for-editing-content/
https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/

And you can use Toolset Access plugin to control access to those post forms
https://toolset.com/course-lesson/controlling-access-to-front-end-forms/

#2240731

Hi Luo,

Thanks for all the links and documentation. I am going to take some time to look through the different links you sent me, I just was wondering about one of my last questions regarding created 3 forms in a row, one underneath the other. So it would look like one long form, the only thing would be to have one submit button for all 3 forms. Is there a simple way to do just that?

Thank You!

#2241163

Nope, as I mentioned above one post form can handle only one post, so each post form need own submit button.

And in your case, it needs to connect posts with post type relationship, so your user need to create those three posts one by one, step by step, for example:
1) Logged-in user create one post of CPT-A, redirect him to a page, show his own "CPT-A" posts:
https://toolset.com/documentation/user-guides/views/filtering-views-query-by-author/
Post author is the same as the logged in user

2) Then user creates posts of other post types( CPT-B, CPT-C ), and related those new posts with his own "CPT-A" post:
https://toolset.com/course-lesson/selecting-parent-posts-when-using-forms-to-create-child-items/

#2245665

My issue is resolved now. Thank you!