# contact-forms/2.3.6/classes/Error/Standard.php

Contact Forms by Cimatti, version 2.3.6. 177 lines.

- Page: https://pluginprobe.com/plugins/contact-forms/2.3.6/code/classes/Error/Standard.php
- Raw: https://pluginprobe.com/plugins/contact-forms/2.3.6/raw/classes/Error/Standard.php
- Modified: 2026-08-05T09:37:24+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.6/code/classes/Error/Standard.php#L10-L20`.

```php
<?php
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.Security.EscapeOutput.HeredocOutputNotEscaped, PluginCheck.CodeAnalysis.Heredoc -- PFBC Error class, HTML/JS output is controlled
class AccuaForm_Error_Standard extends PFBCError {
  protected $errorfound;
  protected $errorsfound;

	public function applyAjaxErrorResponse() {
		$id = $this->form->getId();
		//$errorfound = _accua_forms_json_encode($this->errorfound);
		//$errorsfound = _accua_forms_json_encode($this->errorsfound);
		echo <<<JS
var errorSize = response.errors.length;
var errorHTML = '\\x3Cdiv class="pfbc-error ui-state-error ui-corner-all"\\x3E\\x3Cul\\x3E';
for(e = 0; e < errorSize; ++e) {
  errorHTML += '\\x3Cli\\x3E' + response.errors[e] + '\\x3C/li\\x3E';
}
errorHTML += '\\x3C/ul\\x3E\\x3C/div\\x3E';
jQuery("#$id").append(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) {
			/* Elements with no named input in the DOM (e.g. reCAPTCHA v2) expose their name via data-accua-name */
			field = jQuery('[data-accua-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>';
			
			/* For file inputs with help text, insert error after help text */
			var helpText = field.siblings('.pfbc-help').last();
			if (field.is('[type="file"]') && helpText.length) {
				helpText.after(inlineErrorHTML);
			} else {
				field.after(inlineErrorHTML);
			}
		}
	});
}
JS;

	}

  public function applyAjaxErrorResponseUsingShowErrorMessages() {
    echo <<<JS
var errorSize = response.errors.length;
var errorHTML = '';
for(e = 0; e < errorSize; ++e) {
  errorHTML += '\\x3Cli\\x3E' + response.errors[e] + '\\x3C/li\\x3E';
}

/* Update summary area with server-side errors */
if (typeof updateSummaryWithServerErrors === 'function') {
  updateSummaryWithServerErrors(response.errors, response.elementErrors);
}

/* Apply ARIA attributes and inline errors for accessibility */
if (response.elementErrors) {
  jQuery.each(response.elementErrors, function(fieldName, fieldErrors) {
    var field = jQuery('[name="' + fieldName + '"]');
    if (!field.length) {
      /* Elements with no named input in the DOM (e.g. reCAPTCHA v2) expose their name via data-accua-name */
      field = jQuery('[data-accua-name="' + fieldName + '"]');
    }
    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>';
      
      /* For file inputs with help text, insert error after help text */
      var helpText = field.siblings('.pfbc-help').last();
      if (field.is('[type=\"file\"]') && helpText.length) {
        helpText.after(inlineErrorHTML);
      } else {
        field.after(inlineErrorHTML);
      }
    }
  });
}
JS;

  }
  public function __construct(?array $properties = null) {
    $this->errorfound = __('The following error was found:', 'contact-forms');
    $this->errorsfound = __('The following @errorsize errors were found:', 'contact-forms');
    $this->configure($properties);
  }

  public function setErrorsFound($text = '') {
    $this->errorsfound = $text;
  }

  public function setErrorFound($text = '') {
    $this->errorfound = $text;
  }

	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 = $this->errorfound;
            else
                $format = str_replace('@errorsize', $size, $this->errorsfound);

            echo '<div class="pfbc-error ui-state-error ui-corner-all">', $format, '<ul><li>', implode("</li><li>", $errors), "</li></ul></div>";
        }
    }
    
    public function getAjaxErrorResponse() {
      $flatErrors = $this->parse($this->form->getErrors());
      $elementErrors = $this->form->getErrors(); // Structured errors for ARIA attributes
      return array(
        'errors' => $flatErrors,
        'elementErrors' => $elementErrors
      );
    }

    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
            ));
        }
    }
}

```
