Last active
October 9, 2024 07:15
-
-
Save adczk/2b11e1c1e2510c53328dfab9aab1e8e7 to your computer and use it in GitHub Desktop.
Forminator - repeater fields in e-mail notifications used with individual macro tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: [Forminator] repeater fields in e-mail notifications used with individual macro tags | |
| * Plugin URI: https://premium.wpmudev.org/ | |
| * Description: Use macros like e.g. {text-1-*} in e-mail notification to show all copies of {text-1} repeater field | |
| * wrap these macros between [REPEATER_START] and [REPEATER_END] in your message content, for example: | |
| * [REPEATER_START] {name-1-*} {phone-1-* } [REPEATER_END] | |
| * no matter how many copies are submitted | |
| * Author: adczk (with adjustments of Prashant Singh) | |
| * Author URI: https://premium.wpmudev.org/ | |
| * License: GPLv2 or later | |
| * | |
| * Tested with Forminator 1.23.3 - 1.25.1 | |
| * Update: Aug 25th 2032 - fix for table rendering in Outlook and Apple Mail | |
| * Update: Aug 24th 2023 - bug fix (incorrectly replacing if multiple repeaters) | |
| * | |
| * config in comments | |
| * use as MU plugin | |
| * | |
| */ | |
| add_filter('forminator_replace_form_data', 'wpmudev_show_formatted_data', 10, 3); | |
| function wpmudev_show_formatted_data( $content, $data, $original_data ) { | |
| $form_ids = array( 13327 ); // IDs of forms to apply this to | |
| if ( !in_array( $data['form_id'], $form_ids ) ) { | |
| return $content; | |
| } | |
| if ( strpos( $content, '-*}' ) !== false ) { | |
| $matches = array(); | |
| if ( preg_match_all( '/{([a-z]+)\-\d+\-\*}/', $content, $matches) !== false ) { | |
| foreach( $matches[0] as $macro ) { | |
| if ( strpos( $macro, '-*' ) && !strpos( $macro, 'calculation') ) { | |
| $replacements_count = 0; | |
| $search_macro = ''; | |
| $replacements = '<tr>'; | |
| $main_key = str_replace( '{', '', str_replace( '-*}', '', $macro )); | |
| $the_key = explode( '-', $main_key); | |
| $key_name = $the_key[0]; | |
| $key_id = $the_key[1]; | |
| $replacements .= '<td style="padding: 0.5rem; border: 1px solid #ddd;border-collapse: collapse;">'. $data[$main_key] . '</td>'; | |
| // check and count additional instances | |
| $search_macro = $main_key . '-'; | |
| foreach ( $data as $search_key => $search_value ) { | |
| if ( strpos( $search_key, $search_macro ) !==false ) { | |
| $replacements_count++; | |
| } | |
| } | |
| // if there are, find and add replacements | |
| if ( $replacements_count > 0 ) { | |
| $replacements_count++; | |
| $replacement_id = 2; | |
| for ( $i = 1; $i < $replacements_count; $i++) { | |
| $replacements .= '<td style="padding: 0.5rem; border: 1px solid #ddd;border-collapse:collapse;">'.$data[$key_name.'-'.$key_id.'-'.$replacement_id].'</td>'; | |
| $replacement_id++; | |
| } | |
| } | |
| $replacements .='</tr>'; | |
| $content = str_replace( $macro, $replacements, $content ); | |
| } | |
| } | |
| } | |
| $content = str_replace( '[REPEATER_START]', '<table style="width:100%;margin:10px auto;table-layout:fixed;">', $content ); | |
| $content = str_replace( '[REPEATER_END]', ' </table>', $content ); | |
| } | |
| return $content; | |
| } |
I use forminator version 1.35.1
Author
i have tested it but dont work with calculation field! can you repair / change?
It's possible that I didn't test it with calculation field, don't really remember. But I don't have time to work on this, sorry, maybe some day in future. It is provided "as is" only.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i have tested it
but dont work with calculation field!
can you repair / change?