Problem: I have a Form that includes a custom date field. That date field is used to save a birthdate. I would like to create a conditional group that displays some content in the Form if the birthdate is less than 18 years ago.
Solution: Toolset's date fields store Unix timestamps that represent dates. These are simple numbers. If you want to compare that date to a date in the past, you need to create a Unix timestamp for that date in the past. Then you can compare those two timestamp values like comparing any other numbers. The following custom shortcode can be used to generate a Unix timestamp from the text string "18 years ago":
add_shortcode( 'tssupp-strtotime', 'tssupp_strtotime'); function tssupp_strtotime($atts = []) { $atts = shortcode_atts([ 'string' => '', ], $atts); $time = strtotime($atts['string']); return $time; }
Register tssupp-strtotime in Toolset > Settings > Front-end Content > Functions Inside Conditional Evaluations. Then in the basic Form builder you can implement the shortcode in a conditional like so:
( '$(cliente-data-de-nascimento)' gt '[tssupp-strtotime string="18 years ago"]' )
Or in expert mode:
[cred_show_group if="( '$(cliente-data-de-nascimento)' gt '[tssupp-strtotime string="18 years ago"]' )" mode="fade-slide"] Age is less than 18 [/cred_show_group]
Relevant Documentation:
https://toolset.com/documentation/user-guides/cred-conditional-display-engine/
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 5 years, 1 month ago.
Assisted by: Christian Cox.