builder
4 weeks ago
form-migrator
4 weeks ago
plugin-updates
8 years ago
settings
4 weeks ago
views
4 weeks ago
class-evf-admin-addons.php
4 months ago
class-evf-admin-assets.php
1 week ago
class-evf-admin-builder.php
2 months ago
class-evf-admin-dashboard.php
4 weeks ago
class-evf-admin-editor.php
4 years ago
class-evf-admin-embed-wizard.php
2 years ago
class-evf-admin-entries-table-list.php
2 months ago
class-evf-admin-entries.php
2 months ago
class-evf-admin-form-templates.php
4 weeks ago
class-evf-admin-forms-table-list.php
4 months ago
class-evf-admin-forms.php
4 months ago
class-evf-admin-import-export.php
4 weeks ago
class-evf-admin-menus.php
4 weeks ago
class-evf-admin-notices.php
4 months ago
class-evf-admin-preview-confirmation.php
1 year ago
class-evf-admin-settings.php
4 weeks ago
class-evf-admin-tools.php
2 months ago
class-evf-admin-welcome.php
2 years ago
class-evf-admin.php
2 months ago
class-evf-base-list-table.php
4 months ago
evf-admin-functions.php
4 weeks ago
class-evf-admin-preview-confirmation.php
126 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Preview Confirmation. |
| 4 | * |
| 5 | * @package EverestForms/Admin |
| 6 | * @version 2.0.8 |
| 7 | */ |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Embed Wizard Class. |
| 13 | * |
| 14 | * @since 2.0.8 |
| 15 | */ |
| 16 | class EVF_Admin_Preview_Confirmation { |
| 17 | |
| 18 | /** |
| 19 | * Initialize class. |
| 20 | * |
| 21 | * @since 2.0.8 |
| 22 | */ |
| 23 | public static function init() { |
| 24 | add_action( 'everest_forms_preview_confirmation', array( __CLASS__, 'preview_confirmation' ), 20, 3 ); |
| 25 | add_filter( 'everest_forms_notice_types', array( __CLASS__, 'add_notice' ) ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Add notice type. |
| 30 | * |
| 31 | * @param [array] $notices notices type. |
| 32 | */ |
| 33 | public static function add_notice( $notices ) { |
| 34 | $notices[] = 'preview'; |
| 35 | return $notices; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Show preview confirmation after form submission. |
| 40 | * |
| 41 | * @since 2.0.8 |
| 42 | * |
| 43 | * @param [array] $form_data Form Data. |
| 44 | * @param [array] $form_fields Form Fields. |
| 45 | * @param [string] $preview_style Preview Style. |
| 46 | */ |
| 47 | public static function preview_confirmation( $form_data, $form_fields, $preview_style ) { |
| 48 | |
| 49 | $output = ''; |
| 50 | $output .= '<div class="everest_forms_preview_confirmation_' . $preview_style . '">'; |
| 51 | |
| 52 | $exclude = array( |
| 53 | 'captcha', |
| 54 | 'password', |
| 55 | ); |
| 56 | |
| 57 | $labels = array(); |
| 58 | $fields = array(); |
| 59 | |
| 60 | foreach ( $form_data['form_fields'] as $id => $data ) { |
| 61 | if ( in_array( $data['type'], $exclude, true ) ) { |
| 62 | continue; |
| 63 | } |
| 64 | |
| 65 | $formatted_string = ''; |
| 66 | |
| 67 | if ( isset( $form_fields[ $id ]['type'] ) ) { |
| 68 | if ( has_filter( "everest_forms_field_exporter_{$form_fields[ $id ]['type']}" ) ) { |
| 69 | $formatted_string = apply_filters( "everest_forms_field_exporter_{$form_fields[ $id ]['type']}", $form_fields[ $id ] ); |
| 70 | |
| 71 | if ( false === $formatted_string['value'] || empty( $formatted_string['value'] ) ) { |
| 72 | continue; // Skip empty fields |
| 73 | } |
| 74 | } |
| 75 | } elseif ( empty( $form_fields[ $id ]['value'] ) ) { |
| 76 | continue; // Skip empty fields |
| 77 | } elseif ( 'basic' === $preview_style ) { |
| 78 | $output .= '<div class="everest_forms_preview_confirmation_' . $preview_style . '_label">' . $form_fields[ $id ]['name'] . '<a href="' . esc_url( $form_fields[ $id ]['value'] ) . '" rel="noopener noreferrer" target="_blank"><img src="' . esc_url( $form_fields[ $id ]['value'] ) . '" style="width:200px;" /></a></div>'; |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | if ( isset( $form_fields[ $id ]['type'] ) && 'select' === $form_fields[ $id ]['type'] ) { |
| 83 | $formatted_string = str_replace( '<br>', '', $formatted_string ); |
| 84 | } |
| 85 | |
| 86 | $label = isset( $formatted_string['label'] ) ? $formatted_string['label'] : ''; |
| 87 | |
| 88 | if ( in_array( $label, $labels ) && empty( $formatted_string['value'] ) ) { |
| 89 | continue; // Skip fields with duplicate labels and empty values |
| 90 | } |
| 91 | |
| 92 | $labels[] = $label; |
| 93 | $fields[] = $formatted_string; |
| 94 | |
| 95 | } |
| 96 | |
| 97 | $close_div = 'basic' === $preview_style ? '' : '</div>'; |
| 98 | |
| 99 | foreach ( $fields as $formatted_string ) { |
| 100 | if ( is_array( $formatted_string ) && isset( $formatted_string['label'], $formatted_string['value'] ) ) { |
| 101 | if ( 'basic' === $preview_style ) { |
| 102 | $output .= '<div class="everest_forms_preview_confirmation_' . $preview_style . '_label">' . $formatted_string['label'] . ' : ' . $close_div; |
| 103 | $output .= '<span>' . $formatted_string['value'] . '</span></div>'; |
| 104 | } else { |
| 105 | $output .= '<div class="everest_forms_preview_confirmation_' . $preview_style . '_label">' . $formatted_string['label'] . ' : ' . $close_div; |
| 106 | $output .= '<div class="everest_forms_preview_confirmation_' . $preview_style . '_value">' . $formatted_string['value'] . '</div>'; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | $output .= '</div>'; |
| 112 | |
| 113 | $ajax_form_submission = isset( $form_data['settings']['ajax_form_submission'] ) ? $form_data['settings']['ajax_form_submission'] : 0; |
| 114 | |
| 115 | if ( $ajax_form_submission ) { |
| 116 | return $output; |
| 117 | } else { |
| 118 | evf_add_notice( $output, 'preview' ); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | |
| 123 | } |
| 124 | |
| 125 | EVF_Admin_Preview_Confirmation::init(); |
| 126 |