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

Contact Forms by Cimatti, version 1.9.2. 53 lines.

- Page: https://pluginprobe.com/plugins/contact-forms/1.9.2/code/PFBC/Error/Standard.php
- Raw: https://pluginprobe.com/plugins/contact-forms/1.9.2/raw/PFBC/Error/Standard.php
- Modified: 2023-03-14T12:04:18+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/1.9.2/code/PFBC/Error/Standard.php#L10-L20`.

```php
<?php
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);
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">The following ', $format, ' found:<ul><li>', implode("</li><li>", $errors), "</li></ul></div>";
        }
    }

    public function renderAjaxErrorResponse() {
        $errors = $this->parse($this->form->getErrors());
        if(!empty($errors)) {
            header("Content-type: application/json");
            print _accua_forms_json_encode(array("errors" => $errors));
        }
    }
}

```
