| @@ -1,8 +1,10 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Core\Util; |
| 4 | 4 | |
| 5 | +use BitCode\BitForm\Admin\Form\Helpers; | |
| 6 | + | |
| 5 | 7 | final class FieldValueHandler |
| 6 | 8 | { |
| 7 | 9 | public static function replaceFieldWithValue($stringToReplaceField, $fieldValues) |
| 8 | 10 | { |
| @@ -171,10 +173,11 @@ | ||
| 171 | 173 | |
| 172 | 174 | public static function formatFieldValueForMail($fields, $fieldValues) |
| 173 | 175 | { |
| 174 | 176 | $formattedFldValues = $fieldValues; |
| 175 | - $file_upload_types = ['file-up', 'advanced-file-up']; | |
| 176 | - | |
| 177 | + $repeaterFieldKey = []; | |
| 178 | + $file_upload_types = Helpers::$file_upload_types; | |
| 179 | + $repeated_array_type_data_fields = Helpers::$repeated_array_type_data_fields; | |
| 177 | 180 | foreach ($fields as $fldKey => $fldData) { |
| 178 | 181 | if (in_array($fldData->typ, $file_upload_types)) { |
| 179 | 182 | continue; |
| 180 | 183 | } |
| @@ -184,32 +187,39 @@ | ||
| 184 | 187 | // $formattedFldValues[$fldKey] = htmlspecialchars(implode(', ', $value)); |
| 185 | 188 | // } else { |
| 186 | 189 | // $formattedFldValues[$fldKey] = htmlspecialchars($value); |
| 187 | 190 | // } |
| 191 | + | |
| 188 | 192 | if (is_array($value)) { |
| 189 | - foreach ($value as $subValue) { | |
| 190 | - if (is_array($subValue)) { | |
| 191 | - foreach ($subValue as $subSubKey => $subSubValue) { | |
| 192 | - $stringValue = is_array($subSubValue) ? implode(', ', $subSubValue) : $subSubValue . ', '; | |
| 193 | - $stringValue = htmlspecialchars($stringValue); | |
| 194 | - if (array_key_exists($subSubKey, $formattedFldValues)) { | |
| 195 | - $formattedFldValues[$subSubKey] .= $stringValue; | |
| 193 | + $arrValue = ''; | |
| 194 | + foreach ($value as $v) { | |
| 195 | + if (is_array($v)) { | |
| 196 | + foreach ($v as $k1 => $v1) { | |
| 197 | + if (array_key_exists($k1, $repeaterFieldKey)) { | |
| 198 | + $oldValue = $repeaterFieldKey[$k1]; | |
| 199 | + if (is_array($v1) && in_array($fields->{$k1}->typ, $repeated_array_type_data_fields)) { | |
| 200 | + $newValues = '[' . implode(', ', $v1) . '] '; | |
| 201 | + if (!preg_match('/\[.*\]/', $oldValue)) { | |
| 202 | + $oldValue = '[' . $oldValue . '] '; | |
| 203 | + } | |
| 204 | + } else { | |
| 205 | + $newValues = $v1; | |
| 206 | + } | |
| 207 | + $repeaterFieldKey[$k1] = $oldValue . ', ' . $newValues; | |
| 196 | 208 | } else { |
| 197 | - $formattedFldValues[$subSubKey] = $stringValue; | |
| 209 | + if (!empty($v1) && is_array($v1)) { | |
| 210 | + $repeaterFieldKey[$k1] = htmlspecialchars(implode(', ', $v1)); | |
| 211 | + } else { | |
| 212 | + $repeaterFieldKey[$k1] = htmlspecialchars($v1); | |
| 213 | + } | |
| 198 | 214 | } |
| 199 | 215 | } |
| 200 | 216 | } else { |
| 201 | - if (array_key_exists($fldKey, $formattedFldValues)) { | |
| 202 | - if (is_array($formattedFldValues[$fldKey])) { | |
| 203 | - $formattedFldValues[$fldKey] = htmlspecialchars(implode(', ', $formattedFldValues[$fldKey]) . ', '); | |
| 204 | - } else { | |
| 205 | - $formattedFldValues[$fldKey] .= htmlspecialchars($subValue); | |
| 206 | - } | |
| 207 | - } else { | |
| 208 | - $formattedFldValues[$fldKey] = htmlspecialchars($subValue . ', '); | |
| 209 | - } | |
| 217 | + $arrValue .= $v . ', '; | |
| 210 | 218 | } |
| 211 | 219 | } |
| 220 | + $formattedFldValues[$fldKey] = htmlspecialchars(rtrim($arrValue, ', ')); | |
| 221 | + $arrValue = ''; | |
| 212 | 222 | } else { |
| 213 | 223 | $formattedFldValues[$fldKey] = htmlspecialchars($value); |
| 214 | 224 | } |
| 215 | 225 | if ('textarea' === $fldData->typ) { |
| @@ -220,7 +230,9 @@ | ||
| 220 | 230 | } |
| 221 | 231 | } |
| 222 | 232 | } |
| 223 | 233 | |
| 224 | - return $formattedFldValues; | |
| 234 | + $merge_values = array_merge($fieldValues, $formattedFldValues); | |
| 235 | + $merge_values = array_merge($merge_values, $repeaterFieldKey); | |
| 236 | + return $merge_values; | |
| 225 | 237 | } |
| 226 | 238 | } |