PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Automatically calculating age in words as per user input

  1. Hi,

    I have a school registration form in which there is a date picker for selecting date of birth, there are two more fields in the registration form which should be automatically filled

    Date of Birth (in Words) and
    Age as on 1st April, 2011
    Now these two fields should be automatically filled as per user input on date of birth.

    Could some one please guide me how to do this?

    Form URL = http://www.ppischool.com/admissions/online-registration-2/

    Thanks & Regards
    Vivek
    Deecoup

    Posted 13 years ago on Friday February 25, 2011 | Permalink
  2. This is similar to your other post. It requires custom code and using hooks, filters to read form values and populate others using code.

    There isn't a quick and easy guide as what you want to do is pretty specific. We can provide you with what hooks you would use and a high overview of what you would need to do, but we can't write the custom code for you.

    As with your other question, how skilled are you with PHP and do you know how to use WordPress hooks, actions and filters?

    Posted 13 years ago on Friday February 25, 2011 | Permalink
  3. Yes Please Guide me May be We Can Close one topic.

    Posted 13 years ago on Friday February 25, 2011 | Permalink
  4. Hi Vivek,

    Assuming that the "Date of Birth (in words)" field and the "Age as on 1st April, 2011" should be hidden fields, you can use the gform_pre_submission hook to add the values for this fields after the form has been submitted.

    <?php
    add_action("gform_pre_submission", "pre_submission_handler");
    function pre_submission_handler($form){
        $_POST["input_4"] = "January 13, 1987";
        $_POST["input_71"] = 24;
    }
    ?>

    This is a very basic example of setting these values. You can use the PHP date() function to convert the numeric birth date to words. Here is an easy way to get the person's age:

    http://stackoverflow.com/questions/3380990/php-calculate-persons-current-age

    Posted 13 years ago on Friday February 25, 2011 | Permalink