| @@ -1,69 +1,83 @@ | ||
| 1 | -<?php | |
| 2 | -class AccuaForm_Error_Standard extends PFBCError { | |
| 3 | - protected $errorfound; | |
| 4 | - protected $errorsfound; | |
| 5 | - | |
| 6 | - public function applyAjaxErrorResponse() { | |
| 7 | - $id = $this->form->getId(); | |
| 8 | - //$errorfound = json_encode($this->errorfound); | |
| 9 | - //$errorsfound = json_encode($this->errorsfound); | |
| 10 | - echo <<<JS | |
| 11 | -var errorSize = response.errors.length; | |
| 12 | -var errorHTML = '<div class="pfbc-error ui-state-error ui-corner-all"><ul>'; | |
| 13 | -for(e = 0; e < errorSize; ++e) | |
| 14 | - errorHTML += '<li>' + response.errors[e] + '</li>'; | |
| 15 | -errorHTML += '</ul></div>'; | |
| 16 | -jQuery("#$id").append(errorHTML); | |
| 17 | -JS; | |
| 18 | - | |
| 19 | - } | |
| 20 | - | |
| 21 | - public function __construct(array $properties = null) { | |
| 22 | - $this->errorfound = __('The following error was found:', 'accua-form-api'); | |
| 23 | - $this->errorsfound = __('The following @errorsize errors were found:', 'accua-form-api'); | |
| 24 | - $this->configure($properties); | |
| 25 | - } | |
| 26 | - | |
| 27 | - public function setErrorsFound($text = '') { | |
| 28 | - $this->errorsfound = $text; | |
| 29 | - } | |
| 30 | - | |
| 31 | - public function setErrorFound($text = '') { | |
| 32 | - $this->errorfound = $text; | |
| 33 | - } | |
| 34 | - | |
| 35 | - private function parse($errors) { | |
| 36 | - $list = array(); | |
| 37 | - if(!empty($errors)) { | |
| 38 | - $keys = array_keys($errors); | |
| 39 | - $keySize = sizeof($keys); | |
| 40 | - for($k = 0; $k < $keySize; ++$k) | |
| 41 | - $list = array_merge($list, $errors[$keys[$k]]); | |
| 42 | - } | |
| 43 | - return $list; | |
| 44 | - } | |
| 45 | - | |
| 46 | - public function render() { | |
| 47 | - $errors = $this->parse($this->form->getErrors()); | |
| 48 | - if(!empty($errors)) { | |
| 49 | - $size = sizeof($errors); | |
| 50 | - if($size == 1) | |
| 51 | - $format = $this->errorfound; | |
| 52 | - else | |
| 53 | - $format = str_replace('@errorsize', $size, $this->errorsfound); | |
| 54 | - | |
| 55 | - echo '<div class="pfbc-error ui-state-error ui-corner-all">', $format, '<ul><li>', implode("</li><li>", $errors), "</li></ul></div>"; | |
| 56 | - } | |
| 57 | - } | |
| 58 | - | |
| 59 | - public function renderAjaxErrorResponse($return = false) { | |
| 60 | - $errors = $this->parse($this->form->getErrors()); | |
| 61 | - if ($return) { | |
| 62 | - return $errors; | |
| 63 | - } | |
| 64 | - if(!empty($errors)) { | |
| 65 | - header("Content-type: application/json"); | |
| 66 | - echo json_encode(array("errors" => $errors)); | |
| 67 | - } | |
| 68 | - } | |
| 69 | -} | |
| 1 | +<?php | |
| 2 | +class AccuaForm_Error_Standard extends PFBCError { | |
| 3 | + protected $errorfound; | |
| 4 | + protected $errorsfound; | |
| 5 | + | |
| 6 | + public function applyAjaxErrorResponse() { | |
| 7 | + $id = $this->form->getId(); | |
| 8 | + //$errorfound = _accua_forms_json_encode($this->errorfound); | |
| 9 | + //$errorsfound = _accua_forms_json_encode($this->errorsfound); | |
| 10 | + echo <<<JS | |
| 11 | +var errorSize = response.errors.length; | |
| 12 | +var errorHTML = '\\x3Cdiv class="pfbc-error ui-state-error ui-corner-all"\\x3E\\x3Cul\\x3E'; | |
| 13 | +for(e = 0; e < errorSize; ++e) { | |
| 14 | + errorHTML += '\\x3Cli\\x3E' + response.errors[e] + '\\x3C/li\\x3E'; | |
| 15 | +} | |
| 16 | +errorHTML += '\\x3C/ul\\x3E\\x3C/div\\x3E'; | |
| 17 | +jQuery("#$id").append(errorHTML); | |
| 18 | +JS; | |
| 19 | + | |
| 20 | + } | |
| 21 | + | |
| 22 | + public function applyAjaxErrorResponseUsingShowErrorMessages() { | |
| 23 | + echo <<<JS | |
| 24 | +var errorSize = response.errors.length; | |
| 25 | +var errorHTML = ''; | |
| 26 | +for(e = 0; e < errorSize; ++e) { | |
| 27 | + errorHTML += '\\x3Cli\\x3E' + response.errors[e] + '\\x3C/li\\x3E'; | |
| 28 | +} | |
| 29 | +show_error_messages(errorHTML); | |
| 30 | +JS; | |
| 31 | + | |
| 32 | + } | |
| 33 | + | |
| 34 | + public function __construct(array $properties = null) { | |
| 35 | + $this->errorfound = __('The following error was found:', 'contact-forms'); | |
| 36 | + $this->errorsfound = __('The following @errorsize errors were found:', 'contact-forms'); | |
| 37 | + $this->configure($properties); | |
| 38 | + } | |
| 39 | + | |
| 40 | + public function setErrorsFound($text = '') { | |
| 41 | + $this->errorsfound = $text; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public function setErrorFound($text = '') { | |
| 45 | + $this->errorfound = $text; | |
| 46 | + } | |
| 47 | + | |
| 48 | + private function parse($errors) { | |
| 49 | + $list = array(); | |
| 50 | + if(!empty($errors)) { | |
| 51 | + $keys = array_keys($errors); | |
| 52 | + $keySize = sizeof($keys); | |
| 53 | + for($k = 0; $k < $keySize; ++$k) | |
| 54 | + $list = array_merge($list, $errors[$keys[$k]]); | |
| 55 | + } | |
| 56 | + return $list; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public function render() { | |
| 60 | + $errors = $this->parse($this->form->getErrors()); | |
| 61 | + if(!empty($errors)) { | |
| 62 | + $size = sizeof($errors); | |
| 63 | + if($size == 1) | |
| 64 | + $format = $this->errorfound; | |
| 65 | + else | |
| 66 | + $format = str_replace('@errorsize', $size, $this->errorsfound); | |
| 67 | + | |
| 68 | + echo '<div class="pfbc-error ui-state-error ui-corner-all">', $format, '<ul><li>', implode("</li><li>", $errors), "</li></ul></div>"; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + public function getAjaxErrorResponse() { | |
| 73 | + return $this->parse($this->form->getErrors()); | |
| 74 | + } | |
| 75 | + | |
| 76 | + public function renderAjaxErrorResponse() { | |
| 77 | + $errors = $this->parse($this->form->getErrors()); | |
| 78 | + if(!empty($errors)) { | |
| 79 | + header("Content-type: application/json"); | |
| 80 | + print _accua_forms_json_encode(array("errors" => $errors)); | |
| 81 | + } | |
| 82 | + } | |
| 83 | +} | |