@@ -246,6 +246,7 @@ public static function submitForm($ajax = false) {
246246 }
247247 if (!empty ($ errors )) {
248248 $ app = JFactory::getApplication ();
249+ $ send = false ;
249250 //showing all the validation errors
250251 foreach ($ errors as $ error ) {
251252 $ app ->enqueueMessage (\JText::_ ($ error ), 'error ' );
@@ -256,7 +257,13 @@ public static function submitForm($ajax = false) {
256257 }
257258
258259 if ($ send !== true ) {
259- throw new \Exception (JText::_ ('MOD_JDSCFEMAIL_SEND_ERROR ' ));
260+ switch ($ params ->get ('ajaxsubmit ' ))
261+ {
262+ case 0 : throw new \Exception (JText::_ ('MOD_JDSCFEMAIL_SEND_ERROR ' ));
263+ break ;
264+ case 1 : throw new \Exception (json_encode ($ errors ));
265+ break ;
266+ }
260267 }
261268 $ message = $ params ->get ('thankyou_message ' , '' );
262269 if (empty ($ message )) {
@@ -277,7 +284,7 @@ public static function submitForm($ajax = false) {
277284 }
278285 $ app ->redirect ($ return );
279286 }
280- return ['message ' => $ message , 'redirect ' => $ redirect_url ];
287+ return ['message ' => $ message , 'redirect ' => $ redirect_url, ' errors ' => json_encode ( $ errors ) ];
281288 }
282289
283290 public static function renderVariables ($ variables , $ source ) {
@@ -398,17 +405,17 @@ public static function uploadFile($name, $src) {
398405 else
399406 {
400407 $ tmppath = JPATH_SITE . '/tmp ' ;
401- if (!file_exists ($ tmppath .'/jdscf ' )){
408+ if (!file_exists ($ tmppath .'/jdscf ' )) {
402409 mkdir ($ tmppath .'/jdscf ' ,0777 );
403410 }
404411 $ folder = md5 (time ().'- ' .$ filename .rand (0 ,99999 ));
405- if (!file_exists ($ tmppath .'/jdscf/ ' .$ folder )){
412+ if (!file_exists ($ tmppath .'/jdscf/ ' .$ folder )) {
406413 mkdir ($ tmppath .'/jdscf/ ' .$ folder ,0777 );
407414 }
408415 $ dest = $ tmppath .'/jdscf/ ' .$ folder .'/ ' .$ filename ;
409416
410417 $ return = null ;
411- if (JFile::upload ($ src , $ dest )){
418+ if (JFile::upload ($ src , $ dest )) {
412419 $ return = $ dest ;
413420 }
414421 return $ return ;
0 commit comments