Fixed loop on emty arrays in customFieldsSupport.php that was generating warnings...
authorChuck Scott <cscott@gaslightmedia.com>
Tue, 10 Apr 2018 20:18:57 +0000 (16:18 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Tue, 10 Apr 2018 20:18:57 +0000 (16:18 -0400)
classes/customFieldSupport.php

index 73c16d5..54fa4cf 100644 (file)
@@ -259,9 +259,11 @@ class GlmCustomFieldSupport extends GlmDataFieldsCustomFields
         // Build a list of form field IDs to use in checking for any existing submitted data for this fid and record ID combination
         $fieldIds = '';
         $sep = '';
-        foreach ($submitResult['formFields'] as $field) {
-            $fieldIds .= $sep.$field['id'];
-            $sep = ',';
+        if (is_array($submitResult['formFields']) && count($submitResult['formFields']) > 0) {
+            foreach ($submitResult['formFields'] as $field) {
+                $fieldIds .= $sep.$field['id'];
+                $sep = ',';
+            }
         }
 
         // Get any data already stored for these field IDs / record ID combination
@@ -273,73 +275,76 @@ class GlmCustomFieldSupport extends GlmDataFieldsCustomFields
         $this->wpdb->query("START TRANSACTION");
 
         // For each field
-        foreach ($submitResult['formFields'] as $field) {
-
-            $fType = $field['field_type'];
-
-            // If this is an update of existing data
-            if ($formUpdate) {
-
-                $text_data     = ($fType=='text'||$fType=='textarea'||$fType=='picklist' ? $field['submitted'] : '');
-                $checkbox_data = ($fType=='checkbox' ? $field['submitted'] : false);
-                $integer_data  = ($fType=='integer' ? $field['submitted'] : false);
-                $float_data    = ($fType=='float' ? $field['submitted'] : false);
-                $text_data     = ($fType=='text'||$fType=='picklist' ? $field['submitted'] : '');
-
-                $res = $this->wpdb->update(
-                    GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX.'custom_field_data',
-                    array(
-                        'text_data'     => $text_data,
-                        'checkbox_data' => $checkbox_data,
-                        'integer_data'  => $integer_data,
-                        'float_data'    => $float_data,
-                    ),
-                    array(
-                        'field_id'  => $field['id'],
-                        'record_id' => $recordId
-                    ),
-                    array(
-                        '%s',
-                        '%d',
-                        '%d',
-                        '%f'
-                    ),
-                    array('%d', '%d')
-                );
+        if (is_array($submitResult['formFields']) && count($submitResult['formFields']) > 0) {
+            foreach ($submitResult['formFields'] as $field) {
+
+                $fType = $field['field_type'];
+
+                // If this is an update of existing data
+                if ($formUpdate) {
+
+                    $text_data     = ($fType=='text'||$fType=='textarea'||$fType=='picklist' ? $field['submitted'] : '');
+                    $checkbox_data = ($fType=='checkbox' ? $field['submitted'] : false);
+                    $integer_data  = ($fType=='integer' ? $field['submitted'] : false);
+                    $float_data    = ($fType=='float' ? $field['submitted'] : false);
+                    $text_data     = ($fType=='text'||$fType=='picklist' ? $field['submitted'] : '');
+
+                    $res = $this->wpdb->update(
+                        GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX.'custom_field_data',
+                        array(
+                            'text_data'     => $text_data,
+                            'checkbox_data' => $checkbox_data,
+                            'integer_data'  => $integer_data,
+                            'float_data'    => $float_data,
+                        ),
+                        array(
+                            'field_id'  => $field['id'],
+                            'record_id' => $recordId
+                        ),
+                        array(
+                            '%s',
+                            '%d',
+                            '%d',
+                            '%f'
+                        ),
+                        array('%d', '%d')
+                    );
+
+                } else {
+
+                    $res = $this->wpdb->insert(
+                        GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX.'custom_field_data',
+                        array(
+                            'fid'           => $formId,
+                            'field_id'      => $field['id'],
+                            'record_id'     => $recordId,
+                            'text_data'     => ($fType=='text'||$fType=='textarea'||$fType=='picklist' ? $field['submitted'] : ''),
+                            'checkbox_data' => ($fType=='checkbox' ? $field['submitted'] : false),
+                            'integer_data'  => ($fType=='integer' ? $field['submitted'] : false),
+                            'float_data'    => ($fType=='float' ? $field['submitted'] : false),
+                        ),
+                        array(
+                            '%s',
+                            '%d',
+                            '%d',
+                            '%s',
+                            '%d',
+                            '%d',
+                            '%f'
+                        )
+                    );
 
-            } else {
-
-                $res = $this->wpdb->insert(
-                    GLM_MEMBERS_CUSTOMFIELDS_PLUGIN_DB_PREFIX.'custom_field_data',
-                    array(
-                        'fid'           => $formId,
-                        'field_id'      => $field['id'],
-                        'record_id'     => $recordId,
-                        'text_data'     => ($fType=='text'||$fType=='textarea'||$fType=='picklist' ? $field['submitted'] : ''),
-                        'checkbox_data' => ($fType=='checkbox' ? $field['submitted'] : false),
-                        'integer_data'  => ($fType=='integer' ? $field['submitted'] : false),
-                        'float_data'    => ($fType=='float' ? $field['submitted'] : false),
-                    ),
-                    array(
-                        '%s',
-                        '%d',
-                        '%d',
-                        '%s',
-                        '%d',
-                        '%d',
-                        '%f'
-                    )
-                );
+                }
 
-            }
+                // If there was a failure, roll back all changes
+                if ($res === false) {
+                    $this->wpdb->query("ROLLBACK");
+                    return false;
+                }
 
-            // If there was a failure, roll back all changes
-            if ($res === false) {
-                $this->wpdb->query("ROLLBACK");
-                return false;
             }
 
-        }
+        } // for each field
 
         $this->wpdb->query("COMMIT");