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; }
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.
Get Profile BuilderCombine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.
Get 25% off with the bundle