<?php

/***************************************** for multiselect inputs ****************************************************************************/
//var_dump($field->type);
if ( in_array( $field->type, $multiselect_fields )  ) {
	$multiselect_classes_types = array( 'ginput_container_multiselect' );

	//get the  divs
	$divs = $dom->getElementsByTagName( 'div' );

	$contains_error = false;
	//check if error is present

	foreach ( $divs as $current_div ) {
		$current_div_classes = $current_div->getAttribute( 'class' );
		if ( strpos( $current_div_classes, 'validation_message' ) !== false ) {
			$contains_error = true;
			$current_div->setAttribute( 'class', $current_div->getAttribute( 'class').' invalid-feedback' );
		}
	}


	foreach ( $divs as $div ) {
		$is_valid_input_field = false;
		$div_classes = $div->getAttribute( 'class' );
		$div_classes_array = explode( ' ', $div_classes );
		foreach ( $div_classes_array as $div_class_value ) {
			if ( in_array( $div_class_value, $multiselect_classes_types ) ) {
				$is_valid_input_field = true;
			}
		}

		if ( $is_valid_input_field ) {
			$selects = $dom->getElementsByTagName( 'select' );
			foreach ( $selects as $select ) {
				$select_classes = $select->getAttribute( 'class' );
				if( $contains_error ){
					$select_classes .= ' is-invalid';
				}
				$select->setAttribute( 'class', $select_classes . ' form-control' );
			}
		}		
	}

	$content = utf8_decode($dom->saveHTML($dom->documentElement));
}