Skip Navigation

[Resolved] Associating more than one child on a submission form

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

Problem:

Add custom JS/CSS codes into Toolset Relationship form.

Solution:

The client solved the problem by these:

https://toolset.com/forums/topic/associating-more-than-one-child-on-a-submission-form/#post-2010369

Relevant Documentation:

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

Last updated by igorL-3 3 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2007557

Tell us what you are trying to do? I have a parent post tied DOG. I have made a Post Form for this post and once a new post is created I want to associate more than one child post (the child posts already exist and lets call them BREEDERS and SHOW TITELS). In both cases this is a many-to-many relationships because a DOG can have more than one BREEDER and SHOW TITLES.

I have made relationship forms for BREEDER and SHOW TITLES. I then made a Page called NEW DOG which contains the Post Form for DOG The Template for DOG then contains the Relationship Forms for BREEDER and SHOW TITLES. so that after New Dog is submitted and that post is displayed the template gives an option to link to the child posts for BREEDER and SHOW TITLES. I also selected to Connect a Person to a given DOG as a Breeder and to use the Current Dog. Ive done the same with SHOW TITLES (Connect a Show Title to a given Dog as a Show Title and to use the Current Dog).

In the Relationship forms I selected for the After visitors submit this form: I selected Redirect to the page from where the user came.

This works fine for the first child post link but once that is submitted it doesn’t go to the post but back to the page to enter the New Dog. How can I do this? I want the parent to be pre selected in all cases

I found this link but it’s not quite the same: https://toolset.com/forums/topic/how-to-pre-select-more-than-one-parent-on-a-child-post-submission-form/

Is it possible to do something similar but pre selecting a parent?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#2007949

Hello,

One relationship form can setup only one relationship at the same time, it can not make multiple relationships at the same time.

And the thread you mentioned above is for post form for creating new post, those custom codes won't work in relationship form.

In your case, I suggest you follow our document to setup the relationship form:
https://toolset.com/course-lesson/front-end-relationship-forms-for-connecting-posts/
You can preset the parent dog post in the relationship form, see screenshot in above document:
https://toolset.com/wp-content/uploads/2020/09/toolset-post-relationship-form-selecting-an-action.png

#2008183

Yes I've done that. I'm not trying to set two relationships in one form. I have two relationship forms each setting up one relationship. One form for BREEDER and another form for SHOW TITLES. What I want to do is submin first the DOG form then once that is done submit the BREEDER form. I can do that with no problems becaouse once I submit the DOG Form I'm redirected to the DOG template and from there I can submit the BREEDER form with the parent DOG preselected. The issue then how to submit the SHOW TITELS form with the DOG preselected after I have submitted the BREEDER.

#2009025

This https://toolset.com/forums/topic/relationship-form-not-returning-to-same-page-after-submission/ solves my issue partially.
But I'm unclear about the Note: If a page has multiple relationship forms, including this script in any one of them, should work for all others. Likewise, if you'd like to restrict this script to work on only selective forms on the page, please update the scope of the selector ( .cred_rel_form_class #cred_redirect_url ) accordingly.

I'm not sure where I need to add the extra class to the form. The cred_rel_form_class is added aoutamically when the form is created but where do I add the class so I can restrict the scope of the JS code?

Also the child posts are entered on the post template once it is entered and displayed. However, I need to have a template to display the old posts without the relationship forms. Is that possible?

#2010153

It needs custom JS/CSS codes, please provide a test site with the same problem, fill below private message box with the test site credentials, also point out the problem page/post URL, I need to test and debug it in a live website, thanks

#2010369

Hello,

Unfortunately I can’t do that because I'm working on the site on my local network which is not visable from outsite. Otherwise I'd be happy to grant you access. But your remark about JS/CSS gave me an idea so I added an extra class by doing:

document.getElementsByClassName('cred_rel_form_class')[0].classList.add("myThing");

I have only two forms on the page but

jQuery(document).ready(function() {
jQuery('.myThing #cred_redirect_url').val(window.location);
});

is still acting on both forms: .cred_rel_form_class #cred_redirect_url and .cred_rel_form_class.myThing #cred_redirect_url
I even tried giving the full class name form.cred-form.cred_rel_form_class.myThing #cred_redirect_url in jQuery still the same thing. I'm not able get restrict the scope of jQuery

The .classList.add("myThing"); does work as per output bellow

document.querySelectorAll('.cred_rel_form_class')[0];

<form class="cred-form cred_rel_form_class myThing" method="post" action="/?post_type=dog&p=277181&cred_referrer_form_id=277044" enctype="multipart/form-data" data-bind="with: cred_form_context_e0ba" novalidate="">

document.querySelectorAll('.cred_rel_form_class')[1]

<form class="cred-form cred_rel_form_class" method="post" action="/?post_type=dog&p=277181&cred_referrer_form_id=277044" enctype="multipart/form-data" data-bind="with: cred_form_context_3ab6" novalidate="">

#2011295

My issue is resolved now. Thank you!