Skip Navigation

[Resolved] Conditional frontend form

This support ticket is created 3 years, 7 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: Africa/Casablanca (GMT+01:00)

This topic contains 10 replies, has 2 voices.

Last updated by heikoS 3 years, 7 months ago.

Assisted by: Jamal.

Author
Posts
#1766755

Hi,

I have a page to add a new job offer with a form.
In this form the user have to choose the country, state and city. How can I get it contitional, so the user have to choose the country first, before he can choose the state and after choosing the state he can choose a city.

Important is, that a county contains specified states and the states have specified countries. They are all insert as Custom Post types and in relationship. If I let the user add all three, he can mix it up, which is not in my intererst.

Heiko

#1766893

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

The easiest way, I can imagine, to implement this is using different forms, where each form will redirect to the second one. Similar to a wizard, or a multi-step form.
The first form will create the job offer and redirects it to the second form.
The second form will be an edit form where the user will only choose the country. This form will take the user to the third form.
The third form will be an edit form, where the user will choose the city. And the form will take the user to the fourth form.
The fourth form will be an edit form, where the user will choose the city.

This solution will require some custom code, that will check which country or state has been chosen, to determine the states and the cities that will be displayed in the third and fourth form.

I hope this makes sense. If it does not, please explain what are the relationships that you currently have for your posts and we'll do our best to help.

#1767835

Hi,
thank you for your idea.
I try to make the situation a little bit clearer.

I looked at the real estate site demo. There I've seen, that the states and cities are custom post types. So I created custom post types for country,state and city. I added the cities to the correct states and the states to the country. I also set the relationships, that one county can have many states and so on.

But I can not figure out, how to set a city in conditional from a state and a state in conditional from a county, so if I go to my form for adding a job, the correct county, state and city (in condition) can be added. At least I need a conditional filter on the job search page to filter by country, state and city (in condition).

I tried it out in different ways, but somewhere must be my issue. Perhaps you can bring a little bit light in my thinking.

Thank you in advance and excuse my grammer, it is a litte bit hard for me as a german guy.

#1769523

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Toolset views filters do offer a way to filter by ancestors. This way, when you choose a country on a filter, you can have the state filter to only display that country states and the same for cities.

But, this is not yet, implemented in Toolset Forms. We can work around it with custom code using the Toolset relationship API and the Toolset Forms API.
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
- https://toolset.com/documentation/programmer-reference/cred-api/

Before getting to that part, I would like to ask, what would you store on the Job post related to this?
I assume that you will store the city, in the same way as our Real Estate Demo, right? This means, that Jobs are linked to Cities in a One-to-Many relationship, right?
If that's the case, I can suggest the following steps, that will involve generic fields, read more about it here https://toolset.com/course-lesson/adding-generic-fields-to-forms/
1. Use generic fields for Country, State, and City. Note, that our Demo site, uses a relationship field for the City, but we can't do it here, as it will return all the cities on the database instead of those under a specific state.
2. Conditionally display each field, when the required field is entered. Check the following articles:
- https://toolset.com/course-lesson/conditional-display-for-form-inputs/
- https://toolset.com/documentation/programmer-reference/forms/cred-conditional-display-engine/
3. The country field will use a view that returns all countries.
4. Listen to the country field "change" event, and request the list of states related to the country(using ajax, or REST API), you may want to use select2 input hidden link
Note, that you will need to delay the execution a bit to let Toolset display the state field. Or you may conditionally hide/display the field totally in Javascript custom code.
You will need to use the Relationships API to get the child states of the selected country.
5. Do the same for the City based on the state field change event.
6. Use the "cred_save_data" hook in order to save the City as a relationship to the Job.

I hope this makes sense. Let me know if you have any questions.

#1772001

Hi and sorry for my delay.

The main problem why I have to do this is, that there are some cities having the same name but in a different state. And I did not understand how I can insert this into my form an make it also available in the search on the homepage.

I learn fast, but I am not such good programmer. That is the reason why I choose toolset. So I like to ask you for your further help. Is this a big thing for you or can you do this in a easy way?
If you like to help me out, I give you admin access to my site.

Thank you so far for your informations.

#1772359

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I believe, the easiest way is my first suggestion. The wizard way.

The second suggestion can also be implemented. But it is not as easy as it seems. It will require writing custom code and testing it, which is out of the scope of this support forum.

But, we'll do our best to help you within the scope of our support forum.

So, I suggest, you start building one of those solutions, and get back to us if you got stuck at some point. Provide more details on what you have done so far, and we'll try to help. I activate a private reply, so, you can share credentials to your website safely. ** Make a database backup before sharing credentials. **

At the same time, I must suggest considering hiring one of the contractors. https://toolset.com/contractors/

#1773407

Hi,

thank you for your answer. Before I try to do that on my own, I have a simmilar question.

I made a conditional group in a form, where the user have to choose from a dropdown with parent informations. The parent (company) from the owner is shown. I try to show the group, if the user selected his company.

[ced_show_group if=“ ($ (job-company.parent) ??????? “ mode=„fade-slide“]
[/cred_show_group]

What do I have to fill instead of the ??????? to get this check if it not empty? I read the documentation and try it with some of the booleans like !EMPTY, but nothing is working.

Thank you for helping me to understand toolset a little bit better.

New threads created by Jamal and linked to this one are listed below:

https://toolset.com/forums/topic/conditional-form-on-empty-value/

#1773543

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Sure, I'll help. However, for support rules, we are able to handle only one issue at the time. This helps us to bring you a better service and also helps other users to find all the information here exposed. For that reason, I have created another ticket for this question and I'll post my reply there.
Let's keep this ticket for its original request.

#1778303

Hello Jamal,

the toolset bot told me, that I have to get active with this ticket.
Can you set this ticket longer open please.

I get back to this topic in a few days.

Thank you and have a nice day.

#1778401

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello,

I am setting this ticket as waiting for your reply. It should be kept open for 3 weeks, you will receive 3 email notifications before closure. At that time just write back here and I'll get it in my queue.

Have a nice day as well.

#1782483

My issue is resolved now. Thank you!

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