@@ -139,7 +139,7 @@ public function get_fields() {
139139 $ field ['recaptcha_theme ' ] = isset ( $ field ['recaptcha_theme ' ] ) ? $ field ['recaptcha_theme ' ] : 'light ' ;
140140 }
141141
142- // Check if meta_key has changed for updating old Entries
142+ // Check if meta_key has changed when saving form compared current entries
143143 $ field ['original_name ' ] = $ field ['name ' ];
144144
145145 $ form_fields [] = apply_filters ( 'weforms-get-form-field ' , $ field , $ this ->id );
@@ -377,21 +377,17 @@ public function entries() {
377377 * @param array $form_fields
378378 */
379379
380- public function update_entries ( $ form_id , $ form_fields ) {
380+ public function maybe_update_entries ( $ form_id , $ form_fields ) {
381381 global $ wpdb ;
382- foreach ($ form_fields as $ field ) {
383- $ old_name = $ field ['original_name ' ];
384- $ new_name = $ field ['name ' ];
385- if ($ new_name != $ old_name ) {
386- $ field_to_change = $ field ['original_name ' ];
387- } else {
388- $ field_to_change = " " ;
389- }
390- }
382+ $ changed_fields = $ this ->get_changed_fields ( $ form_fields );
383+
384+ error_log ("Fields to change " . " = " . print_r ($ changed_fields ,1 ));
385+
386+ return ;
391387 $ entries = weforms_get_form_entries ($ form_id );
392- if ($ field_to_change == " " ) {
393- return ;
394- }
388+ // if ($field_to_change == " ") {
389+ // return;
390+ // }
395391 foreach ( $ entries as $ entry ) {
396392 $ entry_id = $ entry ->id ;
397393 $ values = weforms_get_entry_meta ( $ entry_id );
@@ -403,6 +399,33 @@ public function update_entries( $form_id, $form_fields ) {
403399 }
404400 }
405401 }
402+
403+ /**
404+ * Get changed fields of form on Save
405+ * @since 1.6.9
406+ * @param int $form_id
407+ * @param array $form_fields
408+ *
409+ * @return array
410+ */
411+ public function get_changed_fields ( $ form_fields ) {
412+ $ changed_fields = array ();
413+ foreach ($ form_fields as $ field ) {
414+ if ( array_key_exists ( 'original_name ' , $ field ) ) {
415+ $ old_name = $ field ['original_name ' ];
416+ $ new_name = $ field ['name ' ];
417+ } else {
418+ $ old_name = $ field ['name ' ];
419+ $ new_name = $ field ['name ' ];
420+ }
421+ if ($ new_name != $ old_name ) {
422+ $ changed_fields [] = $ field ['original_name ' ];
423+ } else {
424+ continue ;
425+ }
426+ }
427+ return $ changed_fields ;
428+ }
406429
407430 /**
408431 * Get number of form entries
0 commit comments