Skip Navigation

[Resolved] Filter choice on a CRED Form depending on the parent relationships

This support ticket is created 6 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 10 replies, has 2 voices.

Last updated by Christian Cox 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#538089

Hi,

Basically, the idea is :
- the user goes on the page of a Class (Custom Post),
- he uses the CRED form to add a Lesson (Woocommerce Product),
- on this form, he has to select a Classroom (Custom Post, which has Custom Fields),
- but he only has the choice between the Classrooms "assigned" to the Class (that’s my problem).

I did a many-to-many relationship between Class and Classrooms, because a Class can have many Classrooms and a Classroom can be assigned to many Classes.

The Child between the 2 Parents (Class and Classroom) is "Place". Place is also the Parent of Products (=Lessons), I don't know if it's the right thing to do.

With this link I find out how to display Classroom’s custom fields in the Content Template use for Lessons : https://toolset.com/documentation/user-guides/displaying-fields-grandparents/

My problem is : on the CRED Form to add a Lesson (=Product) I used :

[cred_field field='_wpcf_belongs_place_id' value='' order='date' ordering='desc' no_parent_text='No Parent' class='form-control' output='bootstrap']

Unfortunately, the user can make the choice between ALL the Places (child of Class and Classroom). I would like the User could only select one Classroom among the Classrooms assigned to the Class where the Cred Form is displayed.

Was it the good strategy to use many-to-many relationship ? Because Classrooms have Custom Fields I think so.

How to solve this ?

Thanks for your help.

#538318

Hi, let me respond to a couple of things:
Was it the good strategy to use many-to-many relationship ? Because Classrooms have Custom Fields I think so.
I'm not sure how Custom Fields would influence your decision to use a many-to-many relationship or not. You can access information from Custom Fields in posts, their ancestors and descendants in either one-to-many or many-to-many relationships. Since your Classes can occur in multiple Classrooms, and Classrooms can house multiple Classes, this seems like a good use for a many-to-many relationship so I think you've got it right.

I would like the User could only select one Classroom among the Classrooms assigned to the Class where the Cred Form is displayed.
This can be a bit tricky because of all the dependencies, but it's not impossible. Here's a general overview of how I would approach it:
- Hide the automatically generated Place input field using CSS display:none or something similar. The user won't actually select with this field.

- Create a generic select field that contain an option for each Classroom that they can select for this Class. The label of the option can be the Classroom name, and the value can be the ID or slug.
Generic fields in CRED forms:
https://toolset.com/documentation/user-guides/inserting-generic-fields-into-forms/
https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_generic_field

- Create generic select fields - one for each Classroom. Each select field will contain options for all Places that is are children of both the current page (Class) and the selected Classroom. So if you have 5 possible Classrooms, you will have 5 separate generic select fields containing lists of Places. The Places options in each select field will be children of a single Classroom and the current Class. The value of each option should be the Place ID.

- Use CRED conditionals to show and hide the Place select fields based on the selected Classroom. When the user selects Classroom 1, you will hide all the Place select fields except the field related to Classroom 1.
CRED conditionals:
https://toolset.com/documentation/user-guides/conditional-display-for-form-inputs/
https://toolset.com/documentation/user-guides/cred-conditional-display-engine/

- Use the CRED API to capture the selected Place and replace the _wpcf_belongs_place_id value for this Lesson with the user's selected value. We offer a filter - cred_before_save_data - that will allow you to intercept and manipulate these values using PHP before they are saved into the database.
CRED API filter documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

This is a very high-level summary of the approach. If you have specific questions about any of these steps, feel free to create separate tickets for each question. This helps us keep the forum organized, and also helps us provide more understandable information. We'll be glad to help you get it set up correctly.

#538371

Hi Christian,

interesting. Is it going to work with WPML ? Website should be multilingual.

Correct if I'm wrong : everything has to be set on a single CRED Form, right ? Or Do I need a CRED Form per class ?

#538659

Is it going to work with WPML ? Website should be multilingual.
Please give me some more information about how you intend to make the site multilingual.
- Will all Classes be translated into all languages?
- Will all Classrooms be translated into all languages?
- Will all Places be translated into all languages?
- Will all Lessons be translated into all languages?

Correct if I'm wrong : everything has to be set on a single CRED Form, right ? Or Do I need a CRED Form per class ?
A single CRED form will be used for all Classes. Your fields will respond to the current Class page.

#538661

Sorry for the extra post, having some connection issues at the moment.

#538869

Hi Christian,

yes all CP are going to be translated into all languages except Places which is just a "tool", a "bond" between Lessons/Classrooms/Classes.

I read again you first post and I understand it better.It implies everytime I add a Class and/or a Classroom I update the CRED Form, right ?

#539150

It implies everytime I add a Class and/or a Classroom I update the CRED Form, right ?
If you want to hard-code all the Classrooms and Places, then you will need to update the form each time you make changes to these items. However, I do not recommend that approach. Instead I recommend using Views to generate lists of options for each select field, so this form is updated automatically without any manual intervention.

Take a look at this ticket for an explanation of this approach:
https://toolset.com/forums/topic/add-dynamic-cred-generic-field-options-problems-with-html-comments/

all CP are going to be translated into all languages except Places
In order to make this work, it will be required to manually recreate these intermediary connections in all languages once you have translated all the other CPTs. Otherwise, your many-to-many relationships between Classes, Classrooms, and Lessons will not be maintained in secondary languages. This is a limitation of WPML and Toolset that our developers are actively working to overcome, but this feature is still in development.

#539158

Hi Christian,

thank you for your help and explanations.

I still need assistance, but you can close the topic.

I think I'll abandon that part of the website. Too heavy and complex for me, especially for the multilingual part.

I'll wait that limitation of WPML and Toolset disappears before trying to solve that again.

Do you have an idea, even rough idea, when it's going to be "fixed" ?

Thanks

#539223

Too heavy and complex for me, especially for the multilingual part.
I think with a bit of guidance I could help you be more confident. For example, I could set up a demo site where you can see all the moving parts working together. We're here to help as best we can, up to and including implementing these changes for you on your site. If you'd like more assistance feel free to open individual tickets.

Do you have an idea, even rough idea, when it's going to be "fixed" ?
I don't have a number, but I would guess that it is measured in months, not days or weeks. I wouldn't hold up development of a project to wait for it.

#539251

Hi Christian,

yes when I look at the support Toolset provides, I'm sure I can handle it with your help.

The problem is more time. I really have to launch this website and I do it on my free time. So I think it's something I'll try to fix (with your help) later this year.

#539268

I see. Well, good luck!

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