form->getId(); //$errorfound = _accua_forms_json_encode($this->errorfound); //$errorsfound = _accua_forms_json_encode($this->errorsfound); echo <<'; for (var i = 0; i < fieldErrors.length; i++) { inlineErrorHTML += '
' + fieldErrors[i] + '
'; } inlineErrorHTML += ''; /* 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 <<'; for (var i = 0; i < fieldErrors.length; i++) { inlineErrorHTML += '
' + fieldErrors[i] + '
'; } inlineErrorHTML += ''; /* 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 '
', $format, '
  • ', implode("
  • ", $errors), "
"; } } 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 )); } } }