Hi,
on my clients site, you can register for christian events, for example this one: lien caché
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
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:
lien caché
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