jpgoem

forminator-group-repeater-count

May 20th, 2026
29
0
171 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. <?php
  2.  
  3. add_action( 'wp_footer', 'wpmudev_group_repeater_count', 9999 );
  4. function wpmudev_group_repeater_count() {
  5. global $post;
  6. if ( is_a( $post, 'WP_Post' ) && ! has_shortcode( $post->post_content, 'forminator_form' ) ) {
  7. return;
  8. }
  9. ?>
  10. <script type="text/javascript">
  11. jQuery(document).ready(function($){
  12. setTimeout(function() {
  13. $('.forminator-custom-form').trigger('after.load.forminator');
  14. },100);
  15.  
  16. $(document).on('after.load.forminator', function(e, form_id) {
  17. if ( e.target.id == 'forminator-module-1041' || e.target.id == 'forminator-module-693' ) { // Please change the form ID's.
  18. $(document).on('forminator:recalculate', function() {
  19. var participant_count = $( '#group-1 .forminator-grouped-fields' ).length;
  20. $('#calculation-4 input').val(participant_count).trigger('change');
  21. });
  22. $(document).on('forminator:field:condition:toggled', function() {
  23. setTimeout(function() {
  24. var participant_count = $( '#group-1 .forminator-grouped-fields' ).length;
  25. $('#calculation-4 input').val(participant_count).trigger('change');
  26. },1000);
  27. });
  28. }
  29. });
  30. });
  31. </script>
  32. <?php
  33. }
  34.  
  35. add_filter( 'forminator_prepared_data', 'wpmudev_update_pcount_field_val', 10, 2 );
  36. function wpmudev_update_pcount_field_val( $prepared_data, $module_object ){
  37. $form_ids = array( 1041, 693 ); // Please change the form ID's
  38. if ( ! in_array( $module_object->id, $form_ids ) ) {
  39. return $prepared_data;
  40. }
  41.  
  42. if ( !empty ($prepared_data['group-1-copies'] ) ) {
  43. $prepared_data['calculation-4'] += count( $prepared_data['group-1-copies'] );
  44. }
  45.  
  46. return $prepared_data;
  47. }
  48.  
  49. add_action( 'forminator_custom_form_submit_before_set_fields', 'wpmudev_pcount_formula_change', 10, 3 );
  50. function wpmudev_pcount_formula_change( $entry, $module_id, $field_data_array ) {
  51. $form_ids = array( 1041, 693 ); // Please change the form ID.
  52. if ( ! in_array( intval( $module_id ), $form_ids, true ) ) {
  53. return;
  54. }
  55.  
  56. $prepared_data = Forminator_CForm_Front_Action::$prepared_data;
  57. foreach ( $field_data_array as $key => $value ) {
  58. if (( 'calculation-4' === $value['name'] ) && ( !empty( $prepared_data['group-1-copies'] ) ) ) { // Please change the field ID.
  59. Forminator_CForm_Front_Action::$info['field_data_array'][ $key ]['value']['formatting_result'] += count( $prepared_data['group-1-copies'] );
  60. Forminator_CForm_Front_Action::$info['field_data_array'][ $key ]['value']['result'] += count( $prepared_data['group-1-copies'] );
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment