<?php

/***************************************** for Upload Field ****************************************************************************/
//var_dump($field->type);
if ( $field->type === 'fileupload' || $field->type === 'post_image' ) {
	$contains_error = false;
	//check if error is present
	$all_divs = $dom->getElementsByTagName( 'div' );
	foreach ( $all_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' );
		}

		if ( strpos( $current_div_classes, 'ginput_container_fileupload' ) !== false ) {
			$current_div->setAttribute( 'class', $current_div->getAttribute( 'class' ) . ' form-group' );
		}
	}


	$inputs = $dom->getElementsByTagName( 'input' );
	foreach ( $inputs as $input ) {
		$input_type = $input->getAttribute( 'type' );
		if ( $input_type === 'file' || $input_type === 'button' ) {
			$input->setAttribute( 'class', $input->getAttribute( 'class' ) . ' form-control-file' );
			if( $contains_error ){
				$input->setAttribute( 'class', $input->getAttribute( 'class' ) . ' is-invalid ' );
			}
		}
	}
	$content = utf8_decode( $dom->saveHTML( $dom->documentElement ) );
}
	