| @@ -1,12 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * PFBC (PHP Form Builder Class) - Third-party library | |
| 4 | - * @package PFBC | |
| 5 | - */ | |
| 6 | - | |
| 7 | -// phpcs:disable WordPress.Security.EscapeOutput, WordPress.NamingConventions.PrefixAllGlobals, PluginCheck.CodeAnalysis.Heredoc -- Third-party library | |
| 8 | - | |
| 9 | 2 | class Error_Standard extends PFBCError { |
| 10 | 3 | public function applyAjaxErrorResponse() { |
| 11 | 4 | $id = $this->form->getId(); |
| 12 | 5 | echo <<<JS |
| @@ -20,37 +13,8 @@ | ||
| 20 | 13 | for(e = 0; e < errorSize; ++e) |
| 21 | 14 | errorHTML += '<li>' + response.errors[e] + '</li>'; |
| 22 | 15 | errorHTML += '</ul></div>'; |
| 23 | 16 | jQuery("#$id").prepend(errorHTML); |
| 24 | - | |
| 25 | -/* Apply ARIA attributes and inline errors for accessibility */ | |
| 26 | -if (response.elementErrors) { | |
| 27 | - jQuery.each(response.elementErrors, function(fieldName, fieldErrors) { | |
| 28 | - var field = jQuery('[name="' + fieldName + '"]', '#$id'); | |
| 29 | - if (field.length) { | |
| 30 | - var parent = field.closest('.pfbc-element, .pfbc-fieldwrap'); | |
| 31 | - var errorId = field.attr('id') + '-error'; | |
| 32 | - | |
| 33 | - /* Add ARIA attributes */ | |
| 34 | - field.attr('aria-invalid', 'true'); | |
| 35 | - field.attr('aria-describedby', errorId); | |
| 36 | - | |
| 37 | - /* Add error class to parent */ | |
| 38 | - parent.addClass('pfbc-element-has-error'); | |
| 39 | - | |
| 40 | - /* Remove existing inline error if any */ | |
| 41 | - parent.find('.pfbc-inline-error').remove(); | |
| 42 | - | |
| 43 | - /* Add inline error message */ | |
| 44 | - var inlineErrorHTML = '<div class="pfbc-inline-error" id="' + errorId + '" role="alert" aria-live="polite">'; | |
| 45 | - for (var i = 0; i < fieldErrors.length; i++) { | |
| 46 | - inlineErrorHTML += '<div class="pfbc-error-message">' + fieldErrors[i] + '</div>'; | |
| 47 | - } | |
| 48 | - inlineErrorHTML += '</div>'; | |
| 49 | - field.after(inlineErrorHTML); | |
| 50 | - } | |
| 51 | - }); | |
| 52 | -} | |
| 53 | 17 | JS; |
| 54 | 18 | |
| 55 | 19 | } |
| 56 | 20 | |
| @@ -73,23 +37,16 @@ | ||
| 73 | 37 | $format = "error was"; |
| 74 | 38 | else |
| 75 | 39 | $format = $size . " errors were"; |
| 76 | 40 | |
| 77 | - echo '<div class="pfbc-error ui-state-error ui-corner-all" role="alert" aria-live="assertive" tabindex="-1">'; | |
| 78 | - echo '<strong class="pfbc-error-heading">The following ', $format, ' found:</strong>'; | |
| 79 | - echo '<ul class="pfbc-error-list"><li>', implode("</li><li>", $errors), "</li></ul>"; | |
| 80 | - echo '</div>'; | |
| 41 | + echo '<div class="pfbc-error ui-state-error ui-corner-all">The following ', $format, ' found:<ul><li>', implode("</li><li>", $errors), "</li></ul></div>"; | |
| 81 | 42 | } |
| 82 | 43 | } |
| 83 | 44 | |
| 84 | 45 | public function renderAjaxErrorResponse() { |
| 85 | - $flatErrors = $this->parse($this->form->getErrors()); | |
| 86 | - $elementErrors = $this->form->getErrors(); // Keep structured errors for field-level ARIA | |
| 87 | - if(!empty($flatErrors)) { | |
| 46 | + $errors = $this->parse($this->form->getErrors()); | |
| 47 | + if(!empty($errors)) { | |
| 88 | 48 | header("Content-type: application/json"); |
| 89 | - print _accua_forms_json_encode(array( | |
| 90 | - "errors" => $flatErrors, | |
| 91 | - "elementErrors" => $elementErrors // Add field-specific errors for ARIA attributes | |
| 92 | - )); | |
| 49 | + print _accua_forms_json_encode(array("errors" => $errors)); | |
| 93 | 50 | } |
| 94 | 51 | } |
| 95 | 52 | } |