Home Forums Backend Issues (wp-admin) Validate on using value from other field


Validate on using value from other field

  • I’m making something were people can give an start date and ending to an event. The ending date isn’t required but if it has been entered I want to check it with the starting date, as an ending can’t be before an starting date.

    I tried some stuff with acf/validate_value/name=event_end_datetime but I can’t seem to get the correct value from the starting date field (i tried with acf/load_value/name=event_start_datetime but it gives me the value of the field event_start_datetime.

    Here is what I have so far:

    add_filter('acf/validate_value/name=event_end_datetime', 'acf_validate_event_date', 10, 4);
    function acf_validate_event_date($valid, $value, $field, $input){
          //bail early if value is already invalid
          if(!$valid) {
                return $valid;
          //Get value from event_start_datetime
          $event_start_datetime = apply_filters('acf/load_value/name=event_start_datetime', $value);
          //Get value from event_end_datetime
          $event_end_datetime = apply_filters('acf/load_value/name=event_end_datetime', $value);
          //Let's do the check.
          if(strtotime($event_end_datetime) <= strtotime($event_start_datetime) ) {
                $valid = '!Eind datum is ' . $event_end_datetime . ' begin datum is ' . $event_start_datetime;
          $valid = 'Eind datum is ' . $event_end_datetime . ' begin datum is ' . $event_start_datetime;
          return $valid;
  • This reply has been marked as private.
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Validate on using value from other field’ is closed to new replies.