Log server-side validation errors so it is easier to troubleshoot/debug afform issues
authorMatthew Wire <mjw@mjwconsult.co.uk>
Wed, 8 Feb 2023 22:48:25 +0000 (22:48 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 9 Jun 2023 09:38:20 +0000 (10:38 +0100)
ext/afform/core/Civi/Api4/Action/Afform/Submit.php

index 44dc9a5d9daf45a26125fcb5ef76fd839928a058..df072b1d7b6dc385af0fbf558428b6a689dff3b0 100644 (file)
@@ -68,6 +68,7 @@ class Submit extends AbstractProcessor {
     \Civi::dispatcher()->dispatch('civi.afform.validate', $event);
     $errors = $event->getErrors();
     if ($errors) {
+      \Civi::log('afform')->error('Afform Validation errors: ' . print_r($errors, TRUE));
       throw new \CRM_Core_Exception(ts('Validation Error', ['plural' => '%1 Validation Errors', 'count' => count($errors)]), 0, ['validation' => $errors]);
     }
 
@@ -210,7 +211,7 @@ class Submit extends AbstractProcessor {
 
     $isRequired = $attributes['defn']['required'] ?? $fullDefn['required'] ?? FALSE;
     if ($isRequired) {
-      $label = $attributes['defn']['label'] ?? $fullDefn['label'];
+      $label = $attributes['defn']['label'] ?? $fullDefn['label'] ?? $fieldName;
       return E::ts('%1 is a required field.', [1 => $label]);
     }
     return NULL;