A Cozmoslabs Product
Documentation / Developer Knowledge Base / Custom Fields / Date fields are only in the future

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;
}

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.

Get Profile Builder

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket