# contact-forms/2.3.0/PFBC/Error/Standard.php

Contact Forms by Cimatti, version 2.3.0. 96 lines.

- Page: https://pluginprobe.com/plugins/contact-forms/2.3.0/code/PFBC/Error/Standard.php
- Raw: https://pluginprobe.com/plugins/contact-forms/2.3.0/raw/PFBC/Error/Standard.php
- Modified: 2026-04-08T09:49:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/contact-forms/2.3.0/code/PFBC/Error/Standard.php#L10-L20`.

```php
<?php
/**
 * PFBC (PHP Form Builder Class) - Third-party library
 * @package PFBC
 */

// phpcs:disable WordPress.Security.EscapeOutput, WordPress.NamingConventions.PrefixAllGlobals, PluginCheck.CodeAnalysis.Heredoc -- Third-party library

class Error_Standard extends PFBCError {
	public function applyAjaxErrorResponse() {
		$id = $this->form->getId();
		echo <<<JS
var errorSize = response.errors.length;
if(errorSize == 1)
	var errorFormat = "error was";
else
	var errorFormat = errorSize + " errors were";

var errorHTML = '<div class="pfbc-error ui-state-error ui-corner-all">The following ' + errorFormat + ' found:<ul>';
for(e = 0; e < errorSize; ++e)
	errorHTML += '<li>' + response.errors[e] + '</li>';
errorHTML += '</ul></div>';
jQuery("#$id").prepend(errorHTML);

/* Apply ARIA attributes and inline errors for accessibility */
if (response.elementErrors) {
	jQuery.each(response.elementErrors, function(fieldName, fieldErrors) {
		var field = jQuery('[name="' + fieldName + '"]', '#$id');
		if (field.length) {
			var parent = field.closest('.pfbc-element, .pfbc-fieldwrap');
			var errorId = field.attr('id') + '-error';
			
			/* Add ARIA attributes */
			field.attr('aria-invalid', 'true');
			field.attr('aria-describedby', errorId);
			
			/* Add error class to parent */
			parent.addClass('pfbc-element-has-error');
			
			/* Remove existing inline error if any */
			parent.find('.pfbc-inline-error').remove();
			
			/* Add inline error message */
			var inlineErrorHTML = '<div class="pfbc-inline-error" id="' + errorId + '" role="alert" aria-live="polite">';
			for (var i = 0; i < fieldErrors.length; i++) {
				inlineErrorHTML += '<div class="pfbc-error-message">' + fieldErrors[i] + '</div>';
			}
			inlineErrorHTML += '</div>';
			field.after(inlineErrorHTML);
		}
	});
}
JS;

	}

	private function parse($errors) {
		$list = array();
		if(!empty($errors)) {
			$keys = array_keys($errors);
			$keySize = sizeof($keys);
			for($k = 0; $k < $keySize; ++$k)
				$list = array_merge($list, $errors[$keys[$k]]);
		}
		return $list;
	}

    public function render() {
        $errors = $this->parse($this->form->getErrors());
        if(!empty($errors)) {
            $size = sizeof($errors);
            if($size == 1)
                $format = "error was";
            else
                $format = $size . " errors were";

            echo '<div class="pfbc-error ui-state-error ui-corner-all" role="alert" aria-live="assertive" tabindex="-1">';
            echo '<strong class="pfbc-error-heading">The following ', $format, ' found:</strong>';
            echo '<ul class="pfbc-error-list"><li>', implode("</li><li>", $errors), "</li></ul>";
            echo '</div>';
        }
    }

    public function renderAjaxErrorResponse() {
        $flatErrors = $this->parse($this->form->getErrors());
        $elementErrors = $this->form->getErrors(); // Keep structured errors for field-level ARIA
        if(!empty($flatErrors)) {
            header("Content-type: application/json");
            print _accua_forms_json_encode(array(
                "errors" => $flatErrors,
                "elementErrors" => $elementErrors // Add field-specific errors for ARIA attributes
            ));
        }
    }
}

```
