Support

Account

Home Forums ACF PRO Validate 2 fields Reply To: Validate 2 fields

  • All of the field data will be contained in $_POST['acf'] I think. I have not tested this, it is only based on my assumption.

    The indexes of this array are the field key values of the fields. It would depend on your fields. But you can get the value of both fields from the $_POST array and check to make sure that they are both not empty.

    
    add_filter('acf/validate_value/name=first_field_name', 'my_acf_validate_value', 10, 4);
    add_filter('acf/validate_value/name=second_field_name', 'my_acf_validate_value', 10, 4);
    
    function my_acf_validate_value( $valid, $value, $field, $input ){
    	
    	// bail early if value is already invalid
    	if( !$valid ) {
    		return $valid;
    	}
            // get two values
            // you need to change these based on your field keys
    	$value_1 = $_POST['acf']['field_123abc789']
            $value_2 = $_POST['acf']['field_987cba321']
    	if (empty($value_1) && empty($value_2))  {
                $valid = 'Please complete at least one of the fields';
            }
    	// return
    	return $valid;
    	
    	
    }