Skip Navigation

[Resolved] Show Custom Field on form with conditional

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to display parts of a Form depending on a conditional from the current User's profile.

Solution: Use conditional HTML to test any value that is not represented by an input in the Form. Use cred_show_group conditional groups to show and hide parts of the Form based on other input fields in the same Form.

This support ticket is created 4 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
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 2 replies, has 2 voices.

Last updated by MargeP6083 4 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1379123

I am trying to show (or not show) fields on the form input based on age.
https://toolset.com/forums/topic/show-hide-custom-fields-for-users-based-on-age-calculated-from-date-field/

Here are the cred conditionals that are not working for me.Form filed is returning no field (whether I use "lt" or "gt". The logged in user is less than 18. The form field is not showing. I also have the conditional in the custom field conditional display since this needs to have the same conditional on output.

Conditional display: hidden link

Form:
[cred_show_group if="( $(usermeta='date-of-birth' output='raw' user_is_author='true') lt 'YEARS_FROM_NOW(-18)' )" mode="none"]
<div class="form-group">
<label>Parent or Legal Guardian Contact Info</label>
[cred_field field='parent-or-legal-guardian-contact-info' force_type='field' class='form-control' output='bootstrap']
</div>
[/cred_show_group]

Is this the correct syntax? Should I use something else?

Thanks much!

#1379399

Here are the cred conditionals that are not working for me.Form filed is returning no field (whether I use "lt" or "gt". The logged in user is less than 18. The form field is not showing.
Hi, it depends on what you're trying to do here. In general, the cred_show_group syntax is used to show or hide one custom field based on the value of a second custom field that exists in the same Form. As changes are made in the second field, the conditional group is shown or hidden in response to those changes. This syntax should not be used to show or hide fields based on a saved value that is not represented by an input field in the current Form.

If you want to use a conditional based on a field that is not represented in the current Form, it's best to use conditional HTML instead of cred_show_group conditional groups.

So it looks like your conditional group is based on the value of a usermeta date field. If this post does not contain an input field for the date, you should not use cred_show_group. You should use the wpv-conditional syntax instead, as the value of DOB will not change during Form data entry.

#1380405

This makes sense! Thanks! My issue is resolved now.

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