@@ -100,7 +100,6 @@ abstract class Core
100100
101101 protected $ DLTemplate = null ;
102102
103-
104103 /**
105104 * Core constructor.
106105 * @param \DocumentParser $modx
@@ -171,8 +170,11 @@ public function initForm()
171170 $ this ->config ->loadArray ($ this ->getCFGDef ('allowedFields ' )));
172171 $ this ->forbiddenFields = array_merge ($ this ->forbiddenFields ,
173172 $ this ->config ->loadArray ($ this ->getCFGDef ('forbiddenFields ' )));
174- $ this ->emptyFormControls = array_merge ($ this ->emptyFormControls ,
175- $ this ->config ->loadArray ($ this ->getCFGDef ('emptyFormControls ' ), '' ));
173+ $ this ->emptyFormControls = array_merge (
174+ $ this ->emptyFormControls ,
175+ $ this ->config ->loadArray ($ this ->getCFGDef ('emptyFormControls ' ),
176+ ''
177+ ));
176178 $ this ->setRequestParams ();
177179 $ this ->setExternalFields ($ this ->getCFGDef ('defaultsSources ' , 'array ' ));
178180 $ this ->renderTpl = $ this ->getCFGDef ('formTpl ' ); //Шаблон по умолчанию
@@ -425,8 +427,10 @@ public function prerenderForm($convertArraysToStrings = false)
425427 {
426428 if (empty ($ this ->plhCache ) || !$ convertArraysToStrings ) {
427429 $ this ->plhCache = array_merge (
428- $ this ->fieldsToPlaceholders ($ this ->getFormData ('fields ' ), 'value ' ,
429- $ this ->getFormData ('status ' ) || $ convertArraysToStrings ),
430+ $ this ->fieldsToPlaceholders (
431+ $ this ->getFormData ('fields ' ), 'value ' ,
432+ $ this ->getFormData ('status ' ) || $ convertArraysToStrings
433+ ),
430434 $ this ->controlsToPlaceholders (),
431435 $ this ->errorsToPlaceholders (),
432436 array ('form.messages ' => $ this ->renderMessages ())
@@ -561,7 +565,10 @@ public function validate($validator, $rules, $fields)
561565 $ message = $ description ;
562566 }
563567 if (method_exists ($ validator , $ rule )) {
564- $ result = call_user_func_array (array ($ validator , $ rule ), $ params );
568+ $ result = call_user_func_array (
569+ array ($ validator , $ rule ),
570+ $ params
571+ );
565572 } else {
566573 if (isset ($ description ['function ' ])) {
567574 $ rule = $ description ['function ' ];
@@ -855,11 +862,18 @@ public function getValidationRules($param = 'rules')
855862 public function renderMessages ()
856863 {
857864 $ out = '' ;
858- $ formMessages = $ this ->getFormData ('messages ' );
859- $ formErrors = $ this ->getFormData ('errors ' );
860-
861- $ requiredMessages = $ errorMessages = array ();
862- if ($ formErrors ) {
865+ $ wrapper = $ this ->getCFGDef ('messagesTpl ' , '@CODE:<div class="form-messages">[+messages+]</div> ' );
866+ $ formMessages = array_filter ($ this ->getFormData ('messages ' ));
867+ $ plh = array ();
868+ $ plh ['messages ' ] = $ this ->renderMessagesGroup (
869+ $ formMessages ,
870+ 'messagesOuterTpl ' ,
871+ 'messagesSplitter '
872+ );
873+ $ renderErrors = strpos ($ wrapper , '[+errors+] ' ) !== false || strpos ($ wrapper , ['+required+ ' ]) !== false ;
874+ if ($ renderErrors ) {
875+ $ formErrors = array_filter ($ this ->getFormData ('errors ' ));
876+ $ requiredMessages = $ errorMessages = array ();
863877 foreach ($ formErrors as $ field => $ error ) {
864878 $ type = key ($ error );
865879 if ($ type == 'required ' ) {
@@ -868,26 +882,23 @@ public function renderMessages()
868882 $ errorMessages [] = $ error [$ type ];
869883 }
870884 }
885+ if (!empty ($ requiredMessages )) {
886+ $ plh ['required ' ] = $ this ->renderMessagesGroup (
887+ $ requiredMessages ,
888+ 'messagesRequiredOuterTpl ' ,
889+ 'messagesRequiredSplitter '
890+ );
891+ }
892+ if (!empty ($ errorMessages )) {
893+ $ plh ['errors ' ] = $ this ->renderMessagesGroup (
894+ $ errorMessages ,
895+ 'messagesErrorOuterTpl ' ,
896+ 'messagesErrorSplitter '
897+ );
898+ }
871899 }
872- $ wrapper = $ this ->getCFGDef ('messagesTpl ' , '@CODE:<div class="form-messages">[+messages+]</div> ' );
873- $ formMessages = array_filter ($ formMessages );
874- $ formErrors = array_filter ($ formErrors );
875- if (!empty ($ formMessages ) || !empty ($ formErrors )) {
876- $ out = $ this ->parseChunk ($ wrapper ,
877- array (
878- 'messages ' => $ this ->renderMessagesGroup (
879- $ formMessages ,
880- 'messagesOuterTpl ' ,
881- 'messagesSplitter ' ),
882- 'required ' => $ this ->renderMessagesGroup (
883- $ requiredMessages ,
884- 'messagesRequiredOuterTpl ' ,
885- 'messagesRequiredSplitter ' ),
886- 'errors ' => $ this ->renderMessagesGroup (
887- $ errorMessages ,
888- 'messagesErrorOuterTpl ' ,
889- 'messagesErrorSplitter ' ),
890- ));
900+ if (!empty ($ plh ['messages ' ]) || !empty ($ plh ['errors ' ]) || !empty ($ plh ['required ' ])) {
901+ $ out = $ this ->parseChunk ($ wrapper , $ plh );
891902 }
892903
893904 return $ out ;
0 commit comments