|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Gravity Wiz // Gravity Forms // All Fields Template: Compare Template |
| 4 | + * https://gravitywiz.com/gravity-forms-all-fields-template/ |
| 5 | + * |
| 6 | + * Adds a "compare" template to the All Fields Template snippet that displays each field's label, |
| 7 | + * previous value, and current value in a side-by-side CSS grid layout. |
| 8 | + * |
| 9 | + * Instructions: |
| 10 | + * |
| 11 | + * 1. Ensure you have All Fields Template installed. |
| 12 | + * https://gravitywiz.com/gravity-forms-all-fields-template/ |
| 13 | + * |
| 14 | + * 2. Install this snippet. No code configuration required. |
| 15 | + * https://gravitywiz.com/documentation/managing-snippets/#where-do-i-put-snippets |
| 16 | + * |
| 17 | + * 3. Enable the `compare` template on any `{all_fields}` merge tag. Be sure to include the `updated` modifier as well. |
| 18 | + * `{all_fields:updated,template[compare]}` |
| 19 | + */ |
| 20 | +add_filter( 'gwaft_template_output', function( $content, $slug, $name, $data, $suffixes ) { |
| 21 | + if ( ! in_array( 'compare', $suffixes ) ) { |
| 22 | + return $content; |
| 23 | + } |
| 24 | + $original_entry = gw_all_fields_template()->get_original_entry(); |
| 25 | + ?> |
| 26 | + <div class="gwaft-compare-grid"> |
| 27 | + <?php foreach ( $data['items'] as $item ): |
| 28 | + $raw_field_value = GFFormsModel::get_lead_field_value( $original_entry, $item['field'] ); |
| 29 | + $previous_value = GFCommon::get_lead_field_display( $item['field'], $raw_field_value, rgar( $original_entry, 'currency' ), true, 'html', 'email' ); |
| 30 | + ?> |
| 31 | + <div class="gwaft-compare-label"><?php echo $item['label']; ?></div> |
| 32 | + <div class="gwaft-compare-prev"><?php echo $previous_value; ?></div> |
| 33 | + <div class="gwaft-compare-current"><?php echo $item['value']; ?></div> |
| 34 | + <?php endforeach; ?> |
| 35 | + </div> |
| 36 | + <?php |
| 37 | + ?> |
| 38 | + <style> |
| 39 | + .gwaft-compare-grid { |
| 40 | + display: grid; |
| 41 | + grid-template-columns: 1fr 1fr 1fr; |
| 42 | + margin-top: 1rem; |
| 43 | + padding: 0.5rem; |
| 44 | + } |
| 45 | + .gwaft-compare-grid > div { |
| 46 | + padding: 0.5rem; |
| 47 | + border-bottom: 1px solid #ddd; |
| 48 | + } |
| 49 | + .gwaft-compare-label { |
| 50 | + font-weight: bold; |
| 51 | + } |
| 52 | + </style> |
| 53 | + <?php |
| 54 | + return ob_get_clean(); |
| 55 | +}, 10, 5 ); |
0 commit comments