Skip Navigation

[Resolved] Regex and calculating age

This support ticket is created 4 years, 3 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 – 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 4 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1467885

Hi,
on my clients site, you can register for christian events, for example this one: hidden link
If you scroll down, there is the registration form I made with Toolset. As you can see, there are two fields regarding the birthdate and the calculation of your age at the time of the event:
- "Geburtsdatum"
- "Alter bei Veranstaltungsbeginn"
The "Geburtsdatum" is a date picker field as you can see. The "Alter bei Veranstaltungsbeginn" is text, which shows the calculated age after you entered your birthdate in the "Geburtsdatum" datepicker (via JavaScript). It works fine for me and others, but there are also many customers, for which the datepicker filed doesn't work correct for some reason. As a result of this, the client decided to drop the datefield in the upcoming week with a normal text field, where the users enter the birthdate manaually. However, I want to make this text field "sure" with a regular expression in the format of "dd.mm.jjjj". Can I use this the REGEX or DATE function for this?:
https://toolset.com/documentation/user-guides/front-end-forms/cred-conditional-display-engine/
If yes, how do I have to use it? For example there have to be an error message, if the user doesn't fill in the birthdate correctly.
My second question is, if I want to calculate the age via PHP (and not via JavaScript) and want to send the data also in the confimation mail after filling out the form, do I have to use a hook for this?:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

Thanks
Thorsten

#1469271

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Thorsten,

Thank you for contacting us and I'd be happy to assist.

There is no built-in feature available in Toolset which can be used to pre-format the input in a simple text field, but you can use the custom script for this as explained in this tutorial:
hidden link

To validate whether the input text from the user is a valid date or not, you can use a custom PHP function, hooked to "cred_form_validate":
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate

The "cred_before_save_data" hook can be used to process the form's data submitted by the user before it has been saved in the database.
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data

This is useful for the case where your input field's data is in one format and you'd want it to save in the database, in a different format.

For doing some processing when the form's data is being saved, "cred_save_data" hook is also available:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Toolset Forms also allow you to register custom placeholder values, which can be then used in the email notifications. You'll find the details and the example code snippet for this at:
https://toolset.com/documentation/user-guides/front-end-forms/how-to-use-custom-placeholders-in-cred-notifications/

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

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