PluginProbe
Contact Forms by Cimatti / 1.3.8
Contact Forms by Cimatti v1.3.8
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / classes / Error / Standard.php

Standard.php in Contact Forms by Cimatti 1.3.8, at classes/Error/Standard.php

70 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
70