PluginProbe
Contact Forms by Cimatti / 1.9.2
Contact Forms by Cimatti v1.9.2
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 / PFBC / Error / Standard.php

Standard.php in Contact Forms by Cimatti 1.9.2, at PFBC/Error/Standard.php

53 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class Error_Standard extends PFBCError {
3 public function applyAjaxErrorResponse() {
4 $id = $this->form->getId();
5 echo <<<JS
6 var errorSize = response.errors.length;
7 if(errorSize == 1)
8 var errorFormat = "error was";
9 else
10 var errorFormat = errorSize + " errors were";
11
12 var errorHTML = '<div class="pfbc-error ui-state-error ui-corner-all">The following ' + errorFormat + ' found:<ul>';
13 for(e = 0; e < errorSize; ++e)
14 errorHTML += '<li>' + response.errors[e] + '</li>';
15 errorHTML += '</ul></div>';
16 jQuery("#$id").prepend(errorHTML);
17 JS;
18
19 }
20
21 private function parse($errors) {
22 $list = array();
23 if(!empty($errors)) {
24 $keys = array_keys($errors);
25 $keySize = sizeof($keys);
26 for($k = 0; $k < $keySize; ++$k)
27 $list = array_merge($list, $errors[$keys[$k]]);
28 }
29 return $list;
30 }
31
32 public function render() {
33 $errors = $this->parse($this->form->getErrors());
34 if(!empty($errors)) {
35 $size = sizeof($errors);
36 if($size == 1)
37 $format = "error was";
38 else
39 $format = $size . " errors were";
40
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>";
42 }
43 }
44
45 public function renderAjaxErrorResponse() {
46 $errors = $this->parse($this->form->getErrors());
47 if(!empty($errors)) {
48 header("Content-type: application/json");
49 print _accua_forms_json_encode(array("errors" => $errors));
50 }
51 }
52 }
53