Date fields are only in the future

This function makes date fields to be only in the future.

wppb_check_form_field_datepicker is located in Profile Builder: /front-end/extra-fields/datepicker/datepicker.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*
 * Date fields are only in the future.
 */
 
/* handle field validation */
add_filter( 'wppb_check_form_field_datepicker', 'wppbc_dates_in_future', 10, 4 );
function wppbc_dates_in_future( $message, $field, $request_data, $form_location ){
	//var_dump($field);
	//if( $field['field'] == 'Datepicker' && $field['meta-name'] == 'custom_field_1' ){
	if( $field['field'] == 'Datepicker' ){
		if ( isset( $request_data[$field['meta-name']] ) && trim( $request_data[$field['meta-name']] ) != '' ){
			$date = $request_data[$field['meta-name']];
			list($month, $day, $year) = explode('/', $date);
			$timestamp = mktime(0, 0, 0, $month, $day, $year);
			if( $timestamp <= time() ) {
				return 'Please select a date in the future';
			}
 
		}
		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;
}