samedi 19 mars 2016

Calculate Age in Gravity FForms

I'm trying to calculate the age from the date of birth provided by user in Gravity Form. Now the thing is that I want the age to be stored in a hidden field in the gravity form so that I can use conditional login on that hidden field.

I've added a datepicker for the date of birth, but not sure if my function is ok to calculate the exact age and return it to a parameter which I can use in a hidden field.

Here is the code I've written:

add_filter("gform_field_value_age", "_populate_age");
function _populate_age( $result, $value, $form, $field ){
    $age = date('Y') - substr($value, 6, 4);
    return $age;

}

I know my function is wrong but I was hoping someone can help me out on this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire