Skip Navigation

[Resolved] With Toolset Form, display conditional group depending on category checked

This support ticket is created 3 years, 11 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by xavierC-2 3 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1644545

1) I create a form to publish a new Post. On that form, user can choose categories.

2) Once the post is published, the user can edit it with another form and add information.

3) My problem is: I want to display some custom fields depending on categories checked during Step 1). -> If category ID #1 OR #2 checked then display custom fields.

I tried this: [cred_show_group if="($(category) eq '16' )" mode="fade-slide"][/cred_show_group]

I checked this (and more):
https://toolset.com/documentation/user-guides/front-end-forms/cred-conditional-display-engine/

#1645775

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Can you please share the problem URL where I can see the form as well as access details. In addition to that, please mention which field you want to display conditionally.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#1646487

Hello Minesh,

Unfortunately the project is local right now, I cannot share access.

But it's a very generic problem.

Category is the built-in taxonomy of WordPress.

It could be:
- if category checked of the current post has ID #123, then display the CRED group,
OR
- if category checked of the current post has slug 'xyz', then display the CRED group.

I just don't know what to write to specify to check the ID or the slug of the category...

#1646591

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please check the following page: hidden link

Where I have added the taxonomy "Employee Types':

And added the following conditional statement:

[cred_show_group if="( $(employee-type) eq 'Top Performer' )" mode="fade-slide"]
	<div class="form-group">
		<label>Business Email</label>
		[cred_field field='business-email' force_type='field' class='form-control' output='bootstrap']
	</div>[/cred_show_group]

Where:
- as you can see I'm displaying "Employee Types" taxonomy as checkboxes and I've used the checkboxes lable value form comparison and it works.

If you are displaying taxonomy as checkboxes, can you please try to use the checkbox label value and check if that works.

#1646867

I'm sorry it's not working. Also on your example "Top Performer" is not a slug and not an ID. Probably a title. I don't want to use the title...

[credform]
	[cred_field field='form_messages' class='alert alert-warning']
	[cred_show_group if="($(category) eq  '16' )" mode="fade-slide"]Must be displayed if category ID #16 was selected when post was published.[/cred_show_group]
	[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']
[/credform]

Reminder: it's a form to edit, so the category was already selected and saved when the post was first published.

#1647385

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I just would like to have a little additional details. How you displaying the category taxonomy with your form. Is it as checkboxes or dropdown select?

#1647421

I don't understand why it matters. Category taxonomy is not displayed on this form.

1) User creates a new custom post with CRED Form where he chooses one or more categories.

2) User edits the custom post previously created with another CRED form. -> Categories already has been selected on a previous form. I did that because I thought it was necessary to already have that information saved.

#1647489

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It seems you are not getting me what I am asking.
1) User creates a new custom post with CRED Form where he chooses one or more categories.
- OK. How you are displaying the category on this form? as a dropdown select or list of checkboxes? Why I was asking for this because there are two ways you can display taxonomy field with Toolset form. Either checkboxes or dropdown select.

Based on the information you shared with your previous reply:
=> https://toolset.com/forums/topic/with-toolset-form-display-conditional-group-depending-on-category-checked/#post-1646867

I do not see category taxonomy field is added using the [cred-field] shortcode. As you can see with our Doc:
=> https://toolset.com/documentation/user-guides/front-end-forms/cred-conditional-display-engine/#variables

The category taxonomy field should be added to the form (in your case the category field) and with the previous reply you shared, I do not see you have added the category field to your form.

If you just want to display:

[cred_show_group if="($(category) eq  '16' )" mode="fade-slide"]
Must be displayed if category ID #16 was selected when post was published.
[/cred_show_group]

Then, what if you try to change your conditional statement as given under:

[wpv-conditional if="( CONTAINS(#(category),'16') )"]
Must be displayed if category ID #16 was selected when post was published.
[/wpv-conditional]

Does this help?

#1647979

I'll try to fix a misunderstanding going on still the begin of this thread.

User uses Form ABC to create a new custom post, at this step, he chooses categories (WordPress built-in categories).

Then, using other forms, he edits the custom post to add relevant information.

On these other forms, I would like to display conditional groups depending on information the system already has.

I don't want they edit the categories, I don't want they choose new categories. I just would like to display the right fields.

On the form we're concerned here, categories is only an information already registered/saved which is the condition only.

When I create a new conditional group using the GUI, I've choices like "post title", "post excerpt", "featured image" and other custom fields I created with Toolset.

Question is only: how do I use the category of the post as condition?

#1648857

Solution found is to use wpv-conditional rather than a conditional group.

Reminder: I didn't want users could edit the category selection on this form.

[credform]
[cred_field field='form_messages' class='alert alert-warning']
<div>[wpv-conditional if="( '[wpv-post-taxonomy type='category' format='slug']' eq ARRAY('slug1', 'slug2') )" evaluate="true"]add here the fields[/wpv-conditional]</div>
	<div>[cred_field field='form_submit' output='bootstrap' value='Submit' class='btn btn-primary btn-lg']</div>
[/credform]
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.