Skip Navigation

[Résolu] Filtering categories in Forms

This support ticket is created Il y a 2 années et 6 mois. 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
- 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 3 réponses, has 2 voix.

Last updated by Luo Yang Il y a 2 années et 6 mois.

Assisted by: Luo Yang.

Auteur
Publications
#2199639
form.JPG
parent categorie.JPG

Hi,

Is it possible to Filter a credform, while creating a new post?
I have made a form. We have a lot of parent and sub categories.

Here you see the list of the categories
hidden link

Members on our site should be allowed to publish a new article in the catalog.
They have tot choose 1 parent and 1 sub categorie belonging to that parent.
The same with Continents and Countries.

So, is it possible to have the parent cat listed in the first field and the sub cat (child of the choosen parent) in the second field?

#2200375

Hello,

There isn't such kind of built-in feature within Toolset Forms plugin,

You can consider other workaround, for example:
1) Create a page, display a post view with custom search form, setup the taxonomy filters
in view's loop, display a link to another page, and pass term's ID as URL parameter, for example "my-cat=123"

2) In the second page, display the post form for creating post, in the post form output a generic field, set the default value as URL parameter "my-cat" value, for example:

[cred_generic_field type='my-cat' field='category']
{
"default":"[wpv-search-term param='my-cat']"
}
[/cred_generic_field]

https://toolset.com/documentation/programmer-reference/forms/cred-shortcodes/#cred_generic_field

After user submit the form, use action hook "cred_save_data", to trigger a PHP function
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
get the "my-cat" from PHP post variable:
hidden link
And save it into database:
https://developer.wordpress.org/reference/functions/wp_set_object_terms/

#2200785

Hi Luo Yang, thanks for the possible workaround. However, the user of the cred form also needs to be able to select a continent and then the right country within that continent. That would require another page to first select a continent. That continent would then have to be passed to the category selection page, which page would have to pass both the continent and the category to the actual cred form. That would quickly become too complicated as well as not user-friendly. Isn't there a way to have two extra fields in the cred form, to first select a continent and a category, after which the countries to choose from would dynamically be limited to the ones of that continent and the subcategories to choose from would dynamically be limited to the ones of that category? If not, could such a feature not be added?

#2201159

You are right, there isn't such kind of built-in feature within Toolset Forms plugin,
For the question: Isn't there a way to have two extra fields in the cred form ...

It is possible with custom codes, you will need to setup two select fields:
1) the first one get top level terms:
https://developer.wordpress.org/reference/functions/get_terms/
2) After user choose an option in above select field, use AJAX to refresh options of second select field:
https://codex.wordpress.org/AJAX_in_Plugins
And get related second level terms, setup the options

But according to our support policy, we don't provide custom codes support.

you can add a feature request for it:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
Our developers will evaluate it.

You can also check it with Toolset contractors:
https://toolset.com/contractors/

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