In case a datepicker with the “date_of_birth” meta-name selects the birth date, this field makes sure that the user is 18+.
add_filter( 'wppb_check_form_field_datepicker', 'wppbc_custom_18_birthdate_validation', 20, 4 ); function wppbc_custom_18_birthdate_validation( $message, $field, $request_data, $form_location ){ if( $field['field'] == 'Datepicker' && $field['meta-name'] == 'date_of_birth' ){ if ( isset( $request_data[$field['meta-name']] ) && trim( $request_data[$field['meta-name']] ) != '' ){ $input = $request_data[$field['meta-name']]; $birthdate = new DateTime($input); $today = new DateTime('today'); $age = $birthdate->diff($today)->y; if( $age < 18 ) { return 'You need to be at least 18 years old to register for our website.'; } } if ( ( isset( $request_data[$field['meta-name']] ) && ( trim( $request_data[$field['meta-name']] ) == '' ) ) && ( $field['required'] == 'Yes' ) ){ return wppb_required_field_error($field["field-title"]); } } return $message; }
Profile Builder Pro
Create beautiful front-end registration and profile forms with custom fields. Setup member directories, custom redirects, cutomize user emails & more using the all in one user management plugin.
Unlock PRO Features