Support

Account

Home Forums General Issues Validation between to dates

Helping

Validation between to dates

  • Hello,

    Iam have 2 date fields start & end is it possible to limit the number of days between the start and end for example a maximum of 14days so the end date can be any date upto a maximum of 14 days after the start date

    Cheers

    Jon

  • Hello, So I have added the following code to my function.php but for some reason iam not getting any validation and the page is just saved no matter what. Any ideas?

    function my_acf_validate_save_post()
    {
    
    	$start = $_POST['field']['field_591a5d2s941df'];
    	$start = new DateTime($start);
    
    	$end = $_POST['field']['field_539a5a2s921d7a'];
    	$end = new DateTime($end);
    
    	// check custom $_POST data
    		if ($start > $end) {
    			acf_add_validation_error('late_avail_date_end', 'End Date should be greater than or Equal to Start Date');
    		}
    }
    
    add_action('acf/validate_save_post', 'my_acf_validate_save_post', 10, 0);
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Validation between to dates’ is closed to new replies.