0

I need help solving a problem. I am using Ultimate Member plugin for Birth Date validation. I want to check the year the user input from the Data Selection and check to see if they are 13 years or older. I have tried solving it with hooks but it would not allow custom validation on a Date Picker. Here is my code:

    add_action('um_submit_form_errors_hook_student_birthdate','um_custom_validate_birthdate', 999, 1);

    function um_custom_validate_birthdate( $args ) {

       $birthDate = $args['birth_date'];
      //explode the date to get month, day and year
      $birthDate = explode("/", $birthDate);
      //get age from date or birthdate
      $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[1], $birthDate[2], $birthDate[0]))) > date("md")
    ? ((date("Y") - $birthDate[0]) - 1)
    : (date("Y") - $birthDate[0]));

    if ( isset( $args['birth_date'] ) && $age < 13 ) {
        UM()->form()->add_error( 'birth_date', "You must be atleast 13 years old to create an account." );
    }
}

1 Answers1

0

The code is correct.Just I see this this difference with mine:

add_action('um_submit_form_errors_hook_','um_custom_validate_birthdate', 999, 1); instead of yours add_action('um_submit_form_errors_hook_student_birthdate','um_custom_validate_birthdate', 999, 1);

Otherwise is exactly like mine for 18 yo. Maybe simply don't work like you expecting?

With this code, after pressed the registration button, if the age is minor of 13, up the birth date field will appear the message that you put "Sorry you must be 13" or whatever...

If that is what you need it should work. If not work, check your version of the plugin and if you still not updated it to the last verssion, try to do it). If you still have problem, I would advice also to follow their great support forum.

Roberto N
  • 39
  • 6