Calculate user's age using BirthDay field

RSForm!Pro comes with a built-in BirthDay field to use in your forms. Depending on your needs, there may be times when you wish to calculate and store the user's current age. Such scenario can be implemented as instructed below:

1. Fields

  • the BirthDay field: for users to submit their birthday
  • a hidden field: used to store the submitter's age

After the form is submitted, you can use the hidden field's placeholder within the thank-you-message page or the RSForm!Pro generated emails. The placeholder should be similar to: {my-hidden-field-name:value}

2. Script

The following script is added within the "Scripts Called On Form Process" area (backend > Components > RSForm!Pro > Manage Forms > your form > Properties > PHP Scripts). More information on RSForm!Pro PHP Scripts here.

$myBdField = $_POST['form']['my-bday-field-name'];
if(date("md") < date("md", date("U", mktime(0, 0, 0, $myBdField['m'], $myBdField['d'], $myBdField['y'])))){
  $_POST['form']['my-hidden-field-name'] = (date("Y") - $myBdField['y']) - 1;
  $_POST['form']['my-hidden-field-name'] = date("Y") - $myBdField['y'];
Remember to replace:
my-bday-field-name : with your BirthDay field exact name.
my-hidden-field-name : with your hidden field exact name (found twice).

4 persons found this article helpful.

Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Show or hide fields HOT

Fields are not showing up in the frontend HOT

Set up conditionals for groups of fields HOT

Hidden fields take up space in the form

How to copy information from other fields