Skip Navigation

[Resolved] Conditional Fields in CRED form based on Taxonomy selected in custom post type

This support ticket is created 3 years, 5 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 11 replies, has 3 voices.

Last updated by michaelR-26 3 years, 5 months ago.

Assisted by: Raja Mohammed.

Author
Posts
#1837445
Screenshot 2020-11-07 075815.jpg

Tell us what you are trying to do?

I have a taxonomy 'exhibitor-type' and several terms I can select . I this case if I select the term 'Resorts & Travel' in the backend, I would like the front end cred form to only display a certian field when that term is selected.

Here is what I am trying, but it doesn't show the field, instead it keeps it hidden.

[cred_show_group if="($(exhibitor-type) eq 'Resorts & Travel' )" mode='fade-slide']
<br/><br/><label>Welcome Video URL. *YouTube and Vimeo are supported.</label><br/>[cred_field field="welcome-video-url" force_type="field" class="form-control" output="bootstrap"]
[/cred_show_group]

Is there any documentation that you are following?

https://toolset.com/forums/topic/conditional-fields-in-form-based-on-selected-taxonomy-2/

#1838397

Raja Mohammed
Supporter

Languages: English (English )

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

Hello there,

I see that you are using the term name for conditions instead replace the Term name with the term id , Assuming the term id for "Resorts & Travel" as 19 then condition would look like

$(exhibitor-type) eq '19' )

Please refer to the solution on the same thread https://toolset.com/forums/topic/conditional-fields-in-form-based-on-selected-taxonomy-2/#post-627674

Regards
Raja

#1839103

I tried that and it did not work.

When I inspect the term field in the admin I see this. Is my exhibitor type eq to 8, or in-exhibitor-type-8
<input value="8" type="checkbox" name="tax_input[exhibitor-type][]" id="in-exhibitor-type-8" checked="checked">

This is my markup in the cred form:
[cred_show_group if="($(exhibitor-type) eq '8')" mode="fade-slide"]<label>Welcome Video URL. *YouTube and Vimeo are supported.</label><br/>[cred_field field="welcome-video-url" force_type="field" class="form-control" output="bootstrap"][/cred_show_group]

#1839549

Raja Mohammed
Supporter

Languages: English (English )

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

I think I misunderstood your request, you are inserting a form in a page where the taxonomy exhibitor type is selected as Resorts & travels and based on term selected for the post you want to display the fields in the form is that correct ?

Since the taxonomy is already selected for the post, the condition needs to be checked with the post taxonomy in this case use wpv-conditional rather than a conditional group.

[wpv-conditional if="( '[wpv-post-taxonomy type='exhibitor-type' format='id' ]' eq '8' )" ] 
 <label>Welcome Video URL. *YouTube and Vimeo are supported.</label><br/>[cred_field field="welcome-video-url" force_type="field" class="form-control" output="bootstrap"][/wpv-conditional]

I hope this helps better.

Kind regards
Raja

#1843673

I cut and pasted your solutution, but still the field does not display. I double checked to make sure that the taxonomy type was correctly selected in the WordPress admin. It is.

#1845465

Raja Mohammed
Supporter

Languages: English (English )

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

Please share temporary access to your site. Let me check this for you. I am enabling private fields to securely share the details.

Regerds
Raja

#1853351

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi there

Raja is on vacation currently, so I've taken a look at this.

Reading through this, it seems like the question does relate to the conditional display group option in forms (which uses JS to conditionally display content according to changes in selections in field inputs in the form) rather than the wpv-conditional shortcode which is evaluated on the server and is unaffected by subsequent changes to form inputs on the front-end.

It is certainly not clear, but when using a taxonomy for such a condition, the condition must be entered manually, and the value you compare against depends on whether the taxonomy input is displayed as checkboxes or a select dropdown.

If checkboxes, then you should compare against the term name (not slug).

Here's a simple example I verified works on my own test site:

[cred_show_group if="$(colour) eq 'Red'" mode="fade-slide"]<p>The colour is Red</p>[/cred_show_group]

If the taxonomy is displayed as a select then you need to compare with the term id (i.e. a number).

It's confusing, we have an internal ticket to improve this, and I've added your thread to that internal ticket to help bump its priority.

Meanwhile, I visited your site and checked the form. I guess you've done some work on it, as I couldn't find a conditional group for exhibitor-type.

But I did notice a JS error on the page, and as conditional groups work via JS, this will need fixing or they cannot be expected to work.

I looked through the markup of the form, which has been extensively manually edited. I copied it into a code editor to help formatting, and I noticed a problem with the following markup:

                <div class="col-md-6">
                    <div class="form-group">
                        [cred_show_group if="( $(page-header-option) eq '1' )" mode="fade-slide"]
                            <label>Looping Video File - Please choose or upload a video in .mp4 or .mov format, and with a
                                100MB max size. Also, please no sound or word overlays. <span style="color:red;">We
                                    recommend a length between 7 to 30 seconds.</span></label>
                            [cred_field field='header-video-file' force_type='field' output='bootstrap']
                        [/cred_show_group]

                        [cred_show_group if="( $(page-header-option) eq '2' )" mode="fade-slide"]
                        <div class="form-group">
                            <label>Still Shot - Please choose or upload an image that is at least
                                1900px wide by 850px tall. Only .png, .gif and .jpeg formats supported. No words or
                                logos on this image please.</label>
                            [cred_field field='hero-image' force_type='field' output='bootstrap' previewsize='thumbnail']
                        </div>
                    </div> 
                        [/cred_show_group]
                </div>

It's important to realise that whatever occurs inside cred_show_group shortcodes may be excluded in their entirety. The opening and closing divs and opening and closing cred_show_group shortcodes are messed up: if you deleted both cred_show_group blocks the remaining markup would be broken.

So I would first perform a careful inspection of your form to identify such potential problems and fix them.

Then try again with the conditional group that you were having problems with based upon the above directions.

#1853847

In your example

[cred_show_group if="$(colour) eq 'Red'" mode="fade-slide"]<p>The colour is Red</p>[/cred_show_group]

I should replace "colour" with "Exhibitor Type" and "Red" with "Resorts & Travel"? I tried but it does not work.

#1853873

Additionally, I completely removed the section that you said has an error, but still my video URL field will not show.

#1853875

To reiterate.

All I want to do is have this

<span style="color:red;"><b><i>For Ski Resorts Only!</i></b></span>
   <label>Welcome Video URL. *YouTube and Vimeo are supported.</label><br/>[cred_field field="welcome-video-url" force_type="field" class="form-control" output="bootstrap"]

display on the form if, in the WordPress Admin under my custom post type "Exhibitor", the exhibitor has the Taxonomy Term "Resorts & Travel" check box selected.

#1854429

Raja Mohammed
Supporter

Languages: English (English )

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

I have adjusted the the conditionals to check for the slug instead of the id as below, that works well. Since you want to display a field based on the taxonomy of the exhibitor post it is best to use the wpv-conditional in this case.

 [wpv-conditional if="( '[wpv-post-taxonomy type='exhibitor-type' format='slug' ]' eq 'resorts-travel' )" ] <span style="color:red;"><b><i>For Ski Resorts Only!</i></b></span>
   <label>Welcome Video URL. *YouTube and Vimeo are supported.</label><br/>[cred_field field="welcome-video-url" force_type="field" class="form-control" output="bootstrap"][/wpv-conditional]

I have tested that working on your site. Please verify the same.

#1855253

Works perfectly now. I really appreciate the excellent support at ToolSet!!

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