Form_Frontend_Output_Handler::maybe_print_submission_errors( awsmug\Torro_Forms\DB_Objects\Submissions\Submission $submission )

Prints submission errors in a notice if necessary.

Description

Parameters

$submission

(awsmug\Torro_Forms\DB_Objects\Submissions\Submission) (Required) Submission object.

Source

File: src/db-objects/forms/form-frontend-output-handler.php

	protected function maybe_print_submission_errors( $submission ) {
		if ( $submission->has_errors( 0 ) ) {
			$global_errors = $submission->get_errors( 0 );
			if ( 1 === count( $global_errors ) ) {
				$error_key = key( $global_errors );
				$this->print_notice( $global_errors[ $error_key ], 'error' );
			} else {
				?>
				<div class="<?php echo esc_attr( $this->get_notice_class( 'error' ) ); ?>">
					<p><?php _e( 'Some errors occurred while trying to submit the form:', 'torro-forms' ); ?></p>
					<ul>
						<?php foreach ( $global_errors as $error_code => $error_message ) : ?>
							<li><?php echo $error_message; ?></li>
						<?php endforeach; ?>
					</ul>
				</div>
				<?php
			}
		} elseif ( $submission->has_errors() ) {
			$this->print_notice( __( 'Some errors occurred while trying to submit the form.', 'torro-forms' ), 'error' );
		}
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.