@@ -68,6 +68,7 @@ function __construct(FormIt &$formit,array $config = array()) {
6868 'placeholderPrefix ' => 'fi. ' ,
6969 'validationErrorBulkTpl ' => '<li>[[+error]]</li> ' ,
7070 'validationErrorBulkSeparator ' => "\n" ,
71+ 'validationErrorBulkFormatJson ' => false ,
7172 'validationErrorMessage ' => '<p class="error">A form validation error occurred. Please check the values you have entered.</p> ' ,
7273 'use_multibyte ' => (boolean )$ this ->modx ->getOption ('use_multibyte ' ,null ,false ),
7374 'trimValuesBeforeValidation ' => (boolean )$ this ->modx ->getOption ('trimValuesBeforeValidation ' ,$ this ->formit ->config ,true ),
@@ -730,11 +731,18 @@ public function _getErrorMessage($field,$parameter,$lexiconKey,array $properties
730731 public function processErrors () {
731732 $ this ->modx ->toPlaceholders ($ this ->getErrors (),$ this ->config ['placeholderPrefix ' ].'error ' );
732733 $ bulkErrTpl = $ this ->getOption ('validationErrorBulkTpl ' );
734+ $ rawErrs = $ this ->getRawErrors ();
733735 $ errs = array ();
734- foreach ($ this ->getRawErrors () as $ field => $ err ) {
735- $ errs [] = str_replace (array ('[[+field]] ' ,'[[+error]] ' ),array ($ field ,$ err ),$ bulkErrTpl );
736+ $ formatJson = $ this ->getOption ('validationErrorBulkFormatJson ' );
737+ if ($ formatJson ) {
738+ $ errs = '' ;
739+ $ errs = $ this ->modx ->toJSON ($ rawErrs );
740+ } else {
741+ foreach ($ rawErrs as $ field => $ err ) {
742+ $ errs [] = str_replace (array ('[[+field]] ' ,'[[+error]] ' ),array ($ field ,$ err ),$ bulkErrTpl );
743+ }
744+ $ errs = implode ($ this ->getOption ('validationErrorBulkSeparator ' ),$ errs );
736745 }
737- $ errs = implode ($ this ->getOption ('validationErrorBulkSeparator ' ),$ errs );
738746 $ validationErrorMessage = str_replace ('[[+errors]] ' ,$ errs ,$ this ->getOption ('validationErrorMessage ' ));
739747 $ this ->modx ->setPlaceholder ($ this ->getOption ('placeholderPrefix ' ).'validation_error ' ,true );
740748 $ this ->modx ->setPlaceholder ($ this ->getOption ('placeholderPrefix ' ).'validation_error_message ' ,$ validationErrorMessage );
0 commit comments