generate-form-markup.php
| 1 | <?php |
| 2 | /** |
| 3 | * Sureforms Generate Form Class file. |
| 4 | * |
| 5 | * @package sureforms. |
| 6 | * @since 0.0.1 |
| 7 | */ |
| 8 | |
| 9 | namespace SRFM\Inc; |
| 10 | |
| 11 | use SRFM\Inc\Traits\Get_Instance; |
| 12 | |
| 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; // Exit if accessed directly. |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Load Defaults Class. |
| 19 | * |
| 20 | * @since 0.0.1 |
| 21 | */ |
| 22 | class Generate_Form_Markup { |
| 23 | use Get_Instance; |
| 24 | |
| 25 | /** |
| 26 | * Constructor |
| 27 | * |
| 28 | * @since 0.0.1 |
| 29 | */ |
| 30 | public function __construct() { |
| 31 | add_action( 'rest_api_init', [ $this, 'register_custom_endpoint' ] ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Add custom API Route to generate form markup. |
| 36 | * |
| 37 | * @return void |
| 38 | * @since 0.0.1 |
| 39 | */ |
| 40 | public function register_custom_endpoint() { |
| 41 | register_rest_route( |
| 42 | 'sureforms/v1', |
| 43 | '/generate-form-markup', |
| 44 | [ |
| 45 | 'methods' => 'GET', |
| 46 | 'callback' => [ $this, 'get_form_markup' ], |
| 47 | 'permission_callback' => '__return_true', |
| 48 | ] |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Handle Form status |
| 54 | * |
| 55 | * @param int|string $id Contains form ID. |
| 56 | * @param bool $show_title_current_page Boolean to srfm-show/srfm-hide form title. |
| 57 | * @param string $sf_classname additional class_name. |
| 58 | * @param string $post_type Contains post type. |
| 59 | * @param bool $do_blocks Boolean to enable/disable parsing dynamic blocks. |
| 60 | * |
| 61 | * @return string|false |
| 62 | * @since 0.0.1 |
| 63 | */ |
| 64 | public static function get_form_markup( $id, $show_title_current_page = true, $sf_classname = '', $post_type = 'post', $do_blocks = false ) { |
| 65 | if ( isset( $_GET['id'] ) && isset( $_GET['srfm_form_markup_nonce'] ) ) { |
| 66 | $nonce = isset( $_GET['srfm_form_markup_nonce'] ) ? sanitize_text_field( wp_unslash( $_GET['srfm_form_markup_nonce'] ) ) : ''; |
| 67 | $id = wp_verify_nonce( $nonce, 'srfm_form_markup' ) && ! empty( $_GET['srfm_form_markup_nonce'] ) ? Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['id'] ) ) ) : ''; |
| 68 | } else { |
| 69 | $id = Helper::get_integer_value( $id ); |
| 70 | } |
| 71 | do_action( 'srfm_localize_conditional_logic_data', $id ); |
| 72 | $post = get_post( Helper::get_integer_value( $id ) ); |
| 73 | |
| 74 | $content = ''; |
| 75 | |
| 76 | if ( $post && ! empty( $post->post_content ) ) { |
| 77 | if ( ! empty( $do_blocks ) ) { |
| 78 | $content = do_blocks( $post->post_content ); |
| 79 | } else { |
| 80 | $content = apply_filters( 'the_content', $post->post_content ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- wordpress hook |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | $blocks = parse_blocks( $content ); |
| 85 | $block_count = count( $blocks ); |
| 86 | $current_post_type = get_post_type(); |
| 87 | |
| 88 | // load all the frontend assets. |
| 89 | Frontend_Assets::enqueue_scripts_and_styles(); |
| 90 | |
| 91 | ob_start(); |
| 92 | if ( '' !== $id && 0 !== $block_count ) { |
| 93 | |
| 94 | $container_id = 'srfm-form-container-' . Helper::get_string_value( $id ); |
| 95 | $form_styling = get_post_meta( $id, '_srfm_forms_styling', true ); |
| 96 | $form_styling = ! empty( $form_styling ) && is_array( $form_styling ) ? $form_styling : []; |
| 97 | // Background Settings. |
| 98 | $bg_type = $form_styling['bg_type'] ?? 'color'; |
| 99 | $bg_color = $form_styling['bg_color'] ?? ''; |
| 100 | $bg_image = $form_styling['bg_image'] ?? ''; |
| 101 | $bg_image_position = $form_styling['bg_image_position'] ?? []; |
| 102 | $bg_image_attachment = $form_styling['bg_image_attachment'] ?? 'scroll'; |
| 103 | $bg_image_repeat = $form_styling['bg_image_repeat'] ?? 'no-repeat'; |
| 104 | $bg_image_size = $form_styling['bg_image_size'] ?? 'cover'; |
| 105 | $bg_image_size_custom = $form_styling['bg_image_size_custom'] ?? 100; |
| 106 | $bg_image_size_custom_unit = $form_styling['bg_image_size_custom_unit'] ?? '%'; |
| 107 | $bg_gradient = $form_styling['bg_gradient'] ?? 'linear-gradient(90deg, #FFC9B2 0%, #C7CBFF 100%)'; |
| 108 | $gradient_type = $form_styling['gradient_type'] ?? 'basic'; // Basic or advanced. |
| 109 | $is_advanced_gradient = 'advanced' === $gradient_type ? true : false; |
| 110 | $bg_gradient_type = $is_advanced_gradient && isset( $form_styling['bg_gradient_type'] ) ? $form_styling['bg_gradient_type'] : 'linear'; // linear or radial gradient. |
| 111 | $bg_gradient_color_1 = $is_advanced_gradient && isset( $form_styling['bg_gradient_color_1'] ) ? $form_styling['bg_gradient_color_1'] : ''; |
| 112 | $bg_gradient_color_2 = $is_advanced_gradient && isset( $form_styling['bg_gradient_color_2'] ) ? $form_styling['bg_gradient_color_2'] : ''; |
| 113 | $bg_gradient_location_1 = $is_advanced_gradient && isset( $form_styling['bg_gradient_location_1'] ) ? $form_styling['bg_gradient_location_1'] : ''; |
| 114 | $bg_gradient_location_2 = $is_advanced_gradient && isset( $form_styling['bg_gradient_location_2'] ) ? $form_styling['bg_gradient_location_2'] : ''; |
| 115 | $bg_gradient_angle = $is_advanced_gradient && isset( $form_styling['bg_gradient_angle'] ) ? $form_styling['bg_gradient_angle'] : ''; |
| 116 | // Overlay Settings. |
| 117 | $overlay_type = $form_styling['bg_gradient_overlay_type'] ?? ''; |
| 118 | $overlay_size = $form_styling['bg_overlay_size'] ?? 'cover'; |
| 119 | $overlay_opacity = $form_styling['bg_overlay_opacity'] ?? 1; |
| 120 | $overlay_color = $form_styling['bg_image_overlay_color'] ?? ''; |
| 121 | $overlay_image = $form_styling['bg_overlay_image'] ?? ''; |
| 122 | $overlay_position = $form_styling['bg_overlay_position'] ?? []; |
| 123 | $overlay_attachment = $form_styling['bg_overlay_attachment'] ?? 'scroll'; |
| 124 | $overlay_repeat = $form_styling['bg_overlay_repeat'] ?? 'no-repeat'; |
| 125 | $overlay_blend_mode = $form_styling['bg_overlay_blend_mode'] ?? 'normal'; |
| 126 | // Gradient Overlay. |
| 127 | $bg_overlay_gradient = $form_styling['bg_overlay_gradient'] ?? 'linear-gradient(90deg, #FFC9B2 0%, #C7CBFF 100%)'; |
| 128 | $overlay_gradient_type = $form_styling['overlay_gradient_type'] ?? 'basic'; // Basic or advanced. |
| 129 | $is_overlay_advanced_gradient = 'advanced' === $overlay_gradient_type ? true : false; |
| 130 | $bg_overlay_gradient_type = $is_overlay_advanced_gradient && isset( $form_styling['bg_overlay_gradient_type'] ) ? $form_styling['bg_overlay_gradient_type'] : 'linear'; |
| 131 | $bg_overlay_gradient_color_1 = $is_overlay_advanced_gradient && isset( $form_styling['bg_overlay_gradient_color_1'] ) ? $form_styling['bg_overlay_gradient_color_1'] : ''; |
| 132 | $bg_overlay_gradient_color_2 = $is_overlay_advanced_gradient && isset( $form_styling['bg_overlay_gradient_color_2'] ) ? $form_styling['bg_overlay_gradient_color_2'] : ''; |
| 133 | $bg_overlay_gradient_location_1 = $is_overlay_advanced_gradient && isset( $form_styling['bg_overlay_gradient_location_1'] ) ? $form_styling['bg_overlay_gradient_location_1'] : ''; |
| 134 | $bg_overlay_gradient_location_2 = $is_overlay_advanced_gradient && isset( $form_styling['bg_overlay_gradient_location_2'] ) ? $form_styling['bg_overlay_gradient_location_2'] : ''; |
| 135 | $bg_overlay_gradient_angle = $is_overlay_advanced_gradient && isset( $form_styling['bg_overlay_gradient_angle'] ) ? $form_styling['bg_overlay_gradient_angle'] : ''; |
| 136 | // Embed Form Settings. |
| 137 | $form = [ |
| 138 | // Padding. |
| 139 | 'padding_top' => isset( $form_styling['form_padding_top'] ) ? floatval( $form_styling['form_padding_top'] ) : 0, |
| 140 | 'padding_right' => isset( $form_styling['form_padding_right'] ) ? floatval( $form_styling['form_padding_right'] ) : 0, |
| 141 | 'padding_bottom' => isset( $form_styling['form_padding_bottom'] ) ? floatval( $form_styling['form_padding_bottom'] ) : 0, |
| 142 | 'padding_left' => isset( $form_styling['form_padding_left'] ) ? floatval( $form_styling['form_padding_left'] ) : 0, |
| 143 | 'padding_unit' => isset( $form_styling['form_padding_unit'] ) ? Helper::get_string_value( $form_styling['form_padding_unit'] ) : 'px', |
| 144 | // Border Radius. |
| 145 | 'border_radius_top' => isset( $form_styling['form_border_radius_top'] ) ? floatval( $form_styling['form_border_radius_top'] ) : 0, |
| 146 | 'border_radius_right' => isset( $form_styling['form_border_radius_right'] ) ? floatval( $form_styling['form_border_radius_right'] ) : 0, |
| 147 | 'border_radius_bottom' => isset( $form_styling['form_border_radius_bottom'] ) ? floatval( $form_styling['form_border_radius_bottom'] ) : 0, |
| 148 | 'border_radius_left' => isset( $form_styling['form_border_radius_left'] ) ? floatval( $form_styling['form_border_radius_left'] ) : 0, |
| 149 | 'border_radius_unit' => isset( $form_styling['form_border_radius_unit'] ) ? Helper::get_string_value( $form_styling['form_border_radius_unit'] ) : 'px', |
| 150 | ]; |
| 151 | // Instant Form Settings. |
| 152 | $instant_form = [ |
| 153 | // Padding. |
| 154 | 'padding_top' => isset( $form_styling['instant_form_padding_top'] ) ? floatval( $form_styling['instant_form_padding_top'] ) : 32, |
| 155 | 'padding_right' => isset( $form_styling['instant_form_padding_right'] ) ? floatval( $form_styling['instant_form_padding_right'] ) : 32, |
| 156 | 'padding_bottom' => isset( $form_styling['instant_form_padding_bottom'] ) ? floatval( $form_styling['instant_form_padding_bottom'] ) : 32, |
| 157 | 'padding_left' => isset( $form_styling['instant_form_padding_left'] ) ? floatval( $form_styling['instant_form_padding_left'] ) : 32, |
| 158 | 'padding_unit' => isset( $form_styling['instant_form_padding_unit'] ) ? Helper::get_string_value( $form_styling['instant_form_padding_unit'] ) : 'px', |
| 159 | // Border Radius. |
| 160 | 'border_radius_top' => isset( $form_styling['instant_form_border_radius_top'] ) ? floatval( $form_styling['instant_form_border_radius_top'] ) : 12, |
| 161 | 'border_radius_right' => isset( $form_styling['instant_form_border_radius_right'] ) ? floatval( $form_styling['instant_form_border_radius_right'] ) : 12, |
| 162 | 'border_radius_bottom' => isset( $form_styling['instant_form_border_radius_bottom'] ) ? floatval( $form_styling['instant_form_border_radius_bottom'] ) : 12, |
| 163 | 'border_radius_left' => isset( $form_styling['instant_form_border_radius_left'] ) ? floatval( $form_styling['instant_form_border_radius_left'] ) : 12, |
| 164 | 'border_radius_unit' => isset( $form_styling['instant_form_border_radius_unit'] ) ? Helper::get_string_value( $form_styling['instant_form_border_radius_unit'] ) : 'px', |
| 165 | ]; |
| 166 | |
| 167 | if ( 'custom' === $overlay_size ) { |
| 168 | $bg_overlay_custom_size = $form_styling['bg_overlay_custom_size'] ?? 100; |
| 169 | $bg_overlay_custom_size_unit = $form_styling['bg_overlay_custom_size_unit'] ?? '%'; |
| 170 | $overlay_size = $bg_overlay_custom_size . $bg_overlay_custom_size_unit; |
| 171 | } |
| 172 | |
| 173 | $background_classes = apply_filters( 'srfm_add_background_classes', Helper::get_background_classes( $bg_type, $overlay_type, $bg_image ), $id ); |
| 174 | |
| 175 | $neve_theme_margin_class_name = 'srfm-neve-theme-add-margin-bottom'; |
| 176 | $theme_name = wp_get_theme()->get( 'Name' ); |
| 177 | |
| 178 | $form_classes = [ |
| 179 | 'srfm-form-container', |
| 180 | $container_id, |
| 181 | $sf_classname, |
| 182 | 'Neve' === $theme_name ? $neve_theme_margin_class_name : '', // compatibility with Neve theme for margin between main content and footer. |
| 183 | $background_classes, |
| 184 | ]; |
| 185 | |
| 186 | $custom_added_classes = Helper::get_meta_value( $id, '_srfm_additional_classes' ); |
| 187 | if ( ! empty( $custom_added_classes ) && is_string( $custom_added_classes ) ) { |
| 188 | $custom_added_classes = explode( ' ', $custom_added_classes ); |
| 189 | foreach ( $custom_added_classes as $class ) { |
| 190 | if ( Helper::is_valid_css_class_name( $class ) ) { |
| 191 | $form_classes[] = $class; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | $page_break_settings = defined( 'SRFM_PRO_VER' ) && apply_filters( 'srfm_use_page_break_layout', true ) ? get_post_meta( $id, '_srfm_page_break_settings', true ) : []; |
| 197 | $page_break_settings = ! empty( $page_break_settings ) && is_array( $page_break_settings ) ? $page_break_settings : []; |
| 198 | $is_page_break = ! empty( $page_break_settings ) ? $page_break_settings['is_page_break'] : false; |
| 199 | $page_break_progress_type = ! empty( $page_break_settings ) ? $page_break_settings['progress_indicator_type'] : 'none'; |
| 200 | $form_confirmation = get_post_meta( $id, '_srfm_form_confirmation' ); |
| 201 | $confirmation_type = ''; |
| 202 | $submission_action = ''; |
| 203 | $success_url = ''; |
| 204 | if ( is_array( $form_confirmation ) && isset( $form_confirmation[0][0] ) ) { |
| 205 | $confirmation_data = $form_confirmation[0][0]; |
| 206 | $page_url = $confirmation_data['page_url'] ?? ''; |
| 207 | $custom_url = $confirmation_data['custom_url'] ?? ''; |
| 208 | $confirmation_type = $confirmation_data['confirmation_type'] ?? ''; |
| 209 | $submission_action = $confirmation_data['submission_action'] ?? ''; |
| 210 | $success_url = ''; |
| 211 | if ( 'different page' === $confirmation_type ) { |
| 212 | $success_url = $page_url; |
| 213 | } elseif ( 'custom url' === $confirmation_type ) { |
| 214 | $success_url = $custom_url; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | // Submit button. |
| 219 | $button_text = Helper::get_meta_value( $id, '_srfm_submit_button_text' ); |
| 220 | $submit_button_alignment = ! empty( $form_styling['submit_button_alignment'] ) ? $form_styling['submit_button_alignment'] : 'left'; |
| 221 | |
| 222 | if ( is_rtl() && ( 'left' === $submit_button_alignment || 'right' === $submit_button_alignment ) ) { |
| 223 | $submit_button_alignment = 'right' === $submit_button_alignment ? 'left' : 'right'; |
| 224 | } |
| 225 | |
| 226 | $btn_from_theme = Helper::get_meta_value( $id, '_srfm_inherit_theme_button' ); |
| 227 | $is_inline_button = apply_filters( 'srfm_is_inline_button', Helper::get_meta_value( $id, '_srfm_is_inline_button' ) ); |
| 228 | $security_type = Helper::get_meta_value( $id, '_srfm_captcha_security_type' ); |
| 229 | $form_custom_css_meta = Helper::get_meta_value( $id, '_srfm_form_custom_css' ); |
| 230 | $custom_css = ! empty( $form_custom_css_meta ) && is_string( $form_custom_css_meta ) ? $form_custom_css_meta : ''; |
| 231 | |
| 232 | $full = 'justify' === $submit_button_alignment ? true : false; |
| 233 | $recaptcha_version = 'g-recaptcha' === $security_type ? Helper::get_meta_value( $id, '_srfm_form_recaptcha' ) : ''; |
| 234 | $srfm_cf_appearance_mode = ''; |
| 235 | $srfm_cf_turnstile_site_key = ''; |
| 236 | $srfm_hcaptcha_site_key = ''; |
| 237 | |
| 238 | $google_captcha_site_key = ''; |
| 239 | |
| 240 | if ( 'none' !== $security_type ) { |
| 241 | $global_setting_options = get_option( 'srfm_security_settings_options' ); |
| 242 | } else { |
| 243 | $global_setting_options = []; |
| 244 | } |
| 245 | |
| 246 | if ( is_array( $global_setting_options ) && 'cf-turnstile' === $security_type ) { |
| 247 | $srfm_cf_turnstile_site_key = $global_setting_options['srfm_cf_turnstile_site_key'] ?? ''; |
| 248 | $srfm_cf_appearance_mode = $global_setting_options['srfm_cf_appearance_mode'] ?? 'auto'; |
| 249 | } |
| 250 | |
| 251 | if ( is_array( $global_setting_options ) && 'hcaptcha' === $security_type ) { |
| 252 | $srfm_hcaptcha_site_key = $global_setting_options['srfm_hcaptcha_site_key'] ?? ''; |
| 253 | } |
| 254 | |
| 255 | if ( is_array( $global_setting_options ) && 'g-recaptcha' === $security_type ) { |
| 256 | switch ( $recaptcha_version ) { |
| 257 | case 'v2-checkbox': |
| 258 | $google_captcha_site_key = $global_setting_options['srfm_v2_checkbox_site_key'] ?? ''; |
| 259 | break; |
| 260 | case 'v2-invisible': |
| 261 | $google_captcha_site_key = $global_setting_options['srfm_v2_invisible_site_key'] ?? ''; |
| 262 | break; |
| 263 | case 'v3-reCAPTCHA': |
| 264 | $google_captcha_site_key = $global_setting_options['srfm_v3_site_key'] ?? ''; |
| 265 | break; |
| 266 | default: |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Ensure $google_captcha_site_key is not empty, and if not, trim any leading or trailing whitespace. |
| 272 | $google_captcha_site_key = is_string( $google_captcha_site_key ) && ! empty( $google_captcha_site_key ) ? trim( $google_captcha_site_key ) : ''; |
| 273 | |
| 274 | $primary_color = $form_styling['primary_color']; |
| 275 | $help_color_var = $form_styling['text_color']; |
| 276 | $label_text_color = $form_styling['text_color_on_primary']; |
| 277 | $field_spacing = $form_styling['field_spacing']; |
| 278 | |
| 279 | // New colors. |
| 280 | |
| 281 | $primary_color_var = $primary_color ? $primary_color : '#046bd2'; |
| 282 | $label_text_color_var = $label_text_color ? $label_text_color : '#111827'; |
| 283 | |
| 284 | $selected_size = Helper::get_css_vars( $field_spacing ); |
| 285 | |
| 286 | $should_show_submit_button = apply_filters( |
| 287 | 'srfm_show_submit_button', |
| 288 | 0 !== $block_count && ! $is_inline_button || $is_page_break, |
| 289 | $id |
| 290 | ); |
| 291 | |
| 292 | if ( ! $should_show_submit_button ) { |
| 293 | $form_classes[] = 'srfm-submit-button-hidden'; |
| 294 | } |
| 295 | |
| 296 | ?> |
| 297 | <div class="<?php echo esc_attr( implode( ' ', array_filter( $form_classes ) ) ); ?>"> |
| 298 | <style> |
| 299 | /* Need to check and remove the input variables related to the Style Tab. */ |
| 300 | <?php echo esc_html( ".{$container_id}" ); ?> { |
| 301 | /* New test variables */ |
| 302 | --srfm-color-scheme-primary: <?php echo esc_html( $primary_color_var ); ?>; |
| 303 | --srfm-color-scheme-text-on-primary: <?php echo esc_html( $label_text_color_var ); ?>; |
| 304 | --srfm-color-scheme-text: <?php echo esc_html( $help_color_var ); ?>; |
| 305 | --srfm-quill-editor-color: <?php echo esc_html( $primary_color_var ); ?>; |
| 306 | |
| 307 | --srfm-color-input-label: <?php echo esc_html( $help_color_var ); ?>; |
| 308 | --srfm-color-input-description: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.65 ); |
| 309 | --srfm-color-input-placeholder: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.5 ); |
| 310 | --srfm-color-input-text: <?php echo esc_html( $help_color_var ); ?>; |
| 311 | --srfm-color-input-prefix: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.65 ); |
| 312 | --srfm-color-input-background: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.02 ); |
| 313 | --srfm-color-input-background-hover: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.05 ); |
| 314 | --srfm-color-input-background-disabled: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.07 ); |
| 315 | --srfm-color-input-border: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.25 ); |
| 316 | --srfm-color-input-border-disabled: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.15 ); |
| 317 | --srfm-color-multi-choice-svg: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.7 ); |
| 318 | --srfm-color-input-border-hover: hsl( from <?php echo esc_html( $primary_color_var ); ?> h s l / 0.65 ); |
| 319 | --srfm-color-input-border-focus-glow: hsl( from <?php echo esc_html( $primary_color_var ); ?> h s l / 0.15 ); |
| 320 | --srfm-color-input-selected: hsl( from <?php echo esc_html( $primary_color_var ); ?> h s l / 0.1 ); |
| 321 | --srfm-btn-color-hover: hsl( from <?php echo esc_html( $primary_color_var ); ?> h s l / 0.9 ); |
| 322 | --srfm-btn-color-disabled: hsl( from <?php echo esc_html( $primary_color_var ); ?> h s l / 0.25 ); |
| 323 | |
| 324 | /* Dropdown Variables */ |
| 325 | --srfm-dropdown-input-background-hover: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.05 ); |
| 326 | --srfm-dropdown-option-background-hover: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.10 ); |
| 327 | --srfm-dropdown-option-background-selected: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.05 ); |
| 328 | --srfm-dropdown-option-selected-icon: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.65 ); |
| 329 | --srfm-dropdown-option-text-color: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.80 ); |
| 330 | --srfm-dropdown-option-selected-text: <?php echo esc_html( $help_color_var ); ?>; |
| 331 | --srfm-dropdown-badge-background: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.05 ); |
| 332 | --srfm-dropdown-badge-background-hover: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.10 ); |
| 333 | --srfm-dropdown-menu-border-color: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.10 ); |
| 334 | --srfm-dropdown-placeholder-color: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.50 ); |
| 335 | --srfm-dropdown-icon-color: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.65 ); |
| 336 | --srfm-dropdown-icon-disabled: hsl( from <?php echo esc_html( $help_color_var ); ?> h s l / 0.25 ); |
| 337 | |
| 338 | /* Background Control Variables */ |
| 339 | <?php |
| 340 | // Form Styles. |
| 341 | $styling_vars = [ |
| 342 | // Instant Form Padding. |
| 343 | '--srfm-instant-form-padding-top' => sanitize_text_field( "{$instant_form['padding_top']}{$instant_form['padding_unit']}" ), |
| 344 | '--srfm-instant-form-padding-right' => sanitize_text_field( "{$instant_form['padding_right']}{$instant_form['padding_unit']}" ), |
| 345 | '--srfm-instant-form-padding-bottom' => sanitize_text_field( "{$instant_form['padding_bottom']}{$instant_form['padding_unit']}" ), |
| 346 | '--srfm-instant-form-padding-left' => sanitize_text_field( "{$instant_form['padding_left']}{$instant_form['padding_unit']}" ), |
| 347 | // Instant Form Border Radius. |
| 348 | '--srfm-instant-form-border-radius-top' => sanitize_text_field( "{$instant_form['border_radius_top']}{$instant_form['border_radius_unit']}" ), |
| 349 | '--srfm-instant-form-border-radius-right' => sanitize_text_field( "{$instant_form['border_radius_right']}{$instant_form['border_radius_unit']}" ), |
| 350 | '--srfm-instant-form-border-radius-bottom' => sanitize_text_field( "{$instant_form['border_radius_bottom']}{$instant_form['border_radius_unit']}" ), |
| 351 | '--srfm-instant-form-border-radius-left' => sanitize_text_field( "{$instant_form['border_radius_left']}{$instant_form['border_radius_unit']}" ), |
| 352 | // Embed Form Padding. |
| 353 | '--srfm-form-padding-top' => sanitize_text_field( "{$form['padding_top']}{$form['padding_unit']}" ), |
| 354 | '--srfm-form-padding-right' => sanitize_text_field( "{$form['padding_right']}{$form['padding_unit']}" ), |
| 355 | '--srfm-form-padding-bottom' => sanitize_text_field( "{$form['padding_bottom']}{$form['padding_unit']}" ), |
| 356 | '--srfm-form-padding-left' => sanitize_text_field( "{$form['padding_left']}{$form['padding_unit']}" ), |
| 357 | // Embed Form Border Radius. |
| 358 | '--srfm-form-border-radius-top' => sanitize_text_field( "{$form['border_radius_top']}{$form['border_radius_unit']}" ), |
| 359 | '--srfm-form-border-radius-right' => sanitize_text_field( "{$form['border_radius_right']}{$form['border_radius_unit']}" ), |
| 360 | '--srfm-form-border-radius-bottom' => sanitize_text_field( "{$form['border_radius_bottom']}{$form['border_radius_unit']}" ), |
| 361 | '--srfm-form-border-radius-left' => sanitize_text_field( "{$form['border_radius_left']}{$form['border_radius_unit']}" ), |
| 362 | ]; |
| 363 | // Background Styles. |
| 364 | if ( 'image' === $bg_type && ! empty( $bg_image ) ) { |
| 365 | $bg_size_merged = 'custom' === $bg_image_size ? "{$bg_image_size_custom}{$bg_image_size_custom_unit}" : $bg_image_size; |
| 366 | $styling_vars += [ |
| 367 | '--srfm-bg-image' => 'url(' . esc_url_raw( $bg_image ) . ')', |
| 368 | '--srfm-bg-position' => sanitize_text_field( |
| 369 | ( ( ! empty( $bg_image_position['x'] ) ? $bg_image_position['x'] : 0.5 ) * 100 ) . '% ' . |
| 370 | ( ( ! empty( $bg_image_position['y'] ) ? $bg_image_position['y'] : 0.5 ) * 100 ) . '% ' |
| 371 | ), |
| 372 | '--srfm-bg-attachment' => sanitize_text_field( $bg_image_attachment ), |
| 373 | '--srfm-bg-repeat' => sanitize_text_field( $bg_image_repeat ), |
| 374 | '--srfm-bg-size' => sanitize_text_field( $bg_size_merged ), |
| 375 | ]; |
| 376 | } elseif ( 'color' === $bg_type && ! empty( $bg_color ) ) { |
| 377 | $styling_vars['--srfm-bg-color'] = sanitize_text_field( $bg_color ); |
| 378 | } elseif ( 'gradient' === $bg_type && ! empty( $bg_gradient ) ) { |
| 379 | if ( $is_advanced_gradient ) { |
| 380 | $bg_gradient = Helper::get_gradient_css( $bg_gradient_type, $bg_gradient_color_1, $bg_gradient_color_2, $bg_gradient_location_1, $bg_gradient_location_2, $bg_gradient_angle ); |
| 381 | } |
| 382 | $styling_vars['--srfm-bg-gradient'] = sanitize_text_field( $bg_gradient ); |
| 383 | } |
| 384 | // Overlay Variables. |
| 385 | if ( 'image' === $bg_type && 'image' === $overlay_type && ! empty( $overlay_image ) ) { |
| 386 | $styling_vars += [ |
| 387 | '--srfm-bg-overlay-image' => 'url(' . esc_url_raw( $overlay_image ) . ')', |
| 388 | '--srfm-bg-overlay-position' => sanitize_text_field( |
| 389 | ( ( ! empty( $overlay_position['x'] ) ? $overlay_position['x'] : 0.5 ) * 100 ) . '% ' . |
| 390 | ( ( ! empty( $overlay_position['y'] ) ? $overlay_position['y'] : 0.5 ) * 100 ) . '%' |
| 391 | ), |
| 392 | '--srfm-bg-overlay-attachment' => sanitize_text_field( $overlay_attachment ), |
| 393 | '--srfm-bg-overlay-repeat' => sanitize_text_field( $overlay_repeat ), |
| 394 | '--srfm-bg-overlay-size' => sanitize_text_field( $overlay_size ), |
| 395 | '--srfm-bg-overlay-blend-mode' => sanitize_text_field( $overlay_blend_mode ), |
| 396 | ]; |
| 397 | } elseif ( 'image' === $bg_type && 'color' === $overlay_type && ! empty( $overlay_color ) ) { |
| 398 | $styling_vars += [ |
| 399 | '--srfm-bg-overlay-color' => sanitize_text_field( $overlay_color ), |
| 400 | ]; |
| 401 | } elseif ( 'image' === $bg_type && 'gradient' === $overlay_type && ! empty( $bg_overlay_gradient ) ) { |
| 402 | if ( $is_overlay_advanced_gradient ) { |
| 403 | $bg_overlay_gradient = Helper::get_gradient_css( $bg_overlay_gradient_type, $bg_overlay_gradient_color_1, $bg_overlay_gradient_color_2, $bg_overlay_gradient_location_1, $bg_overlay_gradient_location_2, $bg_overlay_gradient_angle ); |
| 404 | } |
| 405 | $styling_vars += [ |
| 406 | '--srfm-bg-overlay-gradient' => sanitize_text_field( $bg_overlay_gradient ), |
| 407 | ]; |
| 408 | } |
| 409 | $styling_vars['--srfm-bg-overlay-opacity'] = floatval( $overlay_opacity ); |
| 410 | // Output the CSS variables. |
| 411 | foreach ( $styling_vars as $key => $value ) { |
| 412 | echo esc_html( Helper::get_string_value( $key ) ) . ': ' . esc_html( Helper::get_string_value( $value ) ) . ';'; |
| 413 | } |
| 414 | ?> |
| 415 | <?php |
| 416 | // Echo the CSS variables for the form according to the field spacing selected. |
| 417 | foreach ( $selected_size as $variable => $value ) { |
| 418 | echo esc_html( Helper::get_string_value( $variable ) ) . ': ' . esc_html( Helper::get_string_value( $value ) ) . ';'; |
| 419 | } |
| 420 | do_action( |
| 421 | 'srfm_form_css_variables', |
| 422 | [ |
| 423 | 'id' => $id, |
| 424 | 'primary_color' => $primary_color_var, |
| 425 | 'help_color' => $help_color_var, |
| 426 | 'form_styling' => $form_styling, |
| 427 | ] |
| 428 | ); |
| 429 | // echo custom css on page/post. |
| 430 | if ( 'sureforms_form' !== $current_post_type ) { |
| 431 | echo wp_kses_post( $custom_css ); |
| 432 | } |
| 433 | ?> |
| 434 | } |
| 435 | </style> |
| 436 | <?php |
| 437 | if ( 'sureforms_form' !== $current_post_type && true === $show_title_current_page ) { |
| 438 | $title = ! empty( get_the_title( (int) $id ) ) ? get_the_title( (int) $id ) : ''; |
| 439 | ?> |
| 440 | <h2 class="srfm-form-title"><?php echo esc_html( $title ); ?></h2> |
| 441 | <?php |
| 442 | } |
| 443 | ?> |
| 444 | <form method="post" enctype="multipart/form-data" id="srfm-form-<?php echo esc_attr( Helper::get_string_value( $id ) ); ?>" class="srfm-form <?php echo esc_attr( 'sureforms_form' === $post_type ? 'srfm-single-form ' : '' ); ?>" |
| 445 | form-id="<?php echo esc_attr( Helper::get_string_value( $id ) ); ?>" after-submission="<?php echo esc_attr( $submission_action ); ?>" message-type="<?php echo esc_attr( $confirmation_type ? $confirmation_type : 'same page' ); ?>" success-url="<?php echo esc_attr( $success_url ? $success_url : '' ); ?>" ajaxurl="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'unique_validation_nonce' ) ); ?>" |
| 446 | > |
| 447 | <?php |
| 448 | wp_nonce_field( 'srfm-form-submit', 'sureforms_form_submit' ); |
| 449 | $global_setting_options = get_option( 'srfm_security_settings_options' ); |
| 450 | $honeypot_spam = is_array( $global_setting_options ) && isset( $global_setting_options['srfm_honeypot'] ) ? $global_setting_options['srfm_honeypot'] : ''; |
| 451 | |
| 452 | if ( $is_page_break && 'none' !== $page_break_progress_type ) { |
| 453 | do_action( 'srfm_page_break_header', $id ); |
| 454 | } |
| 455 | ?> |
| 456 | |
| 457 | <input type="hidden" value="<?php echo esc_attr( Helper::get_string_value( $id ) ); ?>" name="form-id"> |
| 458 | <input type="hidden" value="" name="srfm-sender-email-field" id="srfm-sender-email"> |
| 459 | <input type="hidden" value="<?php echo esc_attr( Helper::get_string_value( $is_page_break ) ); ?>" id="srfm-page-break"> |
| 460 | <?php if ( $honeypot_spam ) { ?> |
| 461 | <input type="hidden" value="" name="srfm-honeypot-field"> |
| 462 | <?php |
| 463 | } |
| 464 | self::common_error_message( 'head' ); |
| 465 | if ( $is_page_break ) { |
| 466 | do_action( 'srfm_page_break_pagination', $post, $id ); |
| 467 | } elseif ( ! apply_filters( 'srfm_use_custom_field_content', false ) ) { |
| 468 | // phpcs:ignore |
| 469 | echo $content; |
| 470 | // phpcs:ignoreEnd |
| 471 | } |
| 472 | |
| 473 | do_action( 'srfm_after_field_content', $post, $id ); |
| 474 | |
| 475 | $captcha_container_hidden_class = ! empty( $google_captcha_site_key ) && ( 'v3-reCAPTCHA' === $recaptcha_version || 'v2-invisible' === $recaptcha_version ) ? 'srfm-display-none' : ''; |
| 476 | |
| 477 | ?> |
| 478 | <?php if ( $should_show_submit_button && ! empty( $security_type ) && 'none' !== $security_type ) { ?> |
| 479 | <div class="srfm-captcha-container <?php echo esc_attr( $captcha_container_hidden_class ); ?>"> |
| 480 | |
| 481 | <?php |
| 482 | |
| 483 | if ( 'g-recaptcha' === $security_type ) { |
| 484 | self::get_google_captcha_script( $recaptcha_version, $google_captcha_site_key ); |
| 485 | } |
| 486 | |
| 487 | if ( 'cf-turnstile' === $security_type ) { |
| 488 | self::get_cf_turnstile_script( $srfm_cf_appearance_mode, $srfm_cf_turnstile_site_key ); |
| 489 | } |
| 490 | |
| 491 | if ( 'hcaptcha' === $security_type ) { |
| 492 | self::get_h_captcha_script( $srfm_hcaptcha_site_key ); |
| 493 | } |
| 494 | ?> |
| 495 | <div class="srfm-validation-error" id="captcha-error" style="display: none;"><?php echo esc_attr__( 'Please verify that you are not a robot.', 'sureforms' ); ?></div> |
| 496 | </div> |
| 497 | <?php } ?> |
| 498 | |
| 499 | <?php |
| 500 | if ( $is_page_break ) { |
| 501 | do_action( 'srfm_page_break_btn', $id ); |
| 502 | } |
| 503 | $srfm_button_classes = apply_filters( 'srfm_add_button_classes', [ '1' === $btn_from_theme ? 'wp-block-button__link' : 'srfm-btn-frontend srfm-button srfm-submit-button', 'v3-reCAPTCHA' === $recaptcha_version ? ' g-recaptcha' : '' ] ); |
| 504 | ?> |
| 505 | |
| 506 | <div class="srfm-submit-container <?php echo esc_attr( $is_page_break ? 'srfm-hide' : '' ); ?>" style="<?php echo ! $should_show_submit_button ? 'visibility:hidden;position:absolute;' : ''; ?>"> |
| 507 | <div style="width: <?php echo esc_attr( $full ? '100%' : '' ); ?>; text-align: <?php echo esc_attr( $submit_button_alignment ); ?>" class="wp-block-button"> |
| 508 | <?php do_action( 'srfm_before_submit_button', $id ); ?> |
| 509 | <button style="<?php echo esc_attr( $full ? 'width: 100%;' : '' ); ?>" id="srfm-submit-btn" class="<?php echo esc_attr( implode( ' ', array_filter( $srfm_button_classes ) ) ); ?>" |
| 510 | <?php if ( $should_show_submit_button && 'v3-reCAPTCHA' === $recaptcha_version ) { ?> |
| 511 | data-callback="recaptchaCallback" |
| 512 | data-error-callback="onGCaptchaV3Error" |
| 513 | recaptcha-type="<?php echo esc_attr( $recaptcha_version ); ?>" |
| 514 | data-sitekey="<?php echo esc_attr( $google_captcha_site_key ); ?>" |
| 515 | <?php } ?> |
| 516 | > |
| 517 | <div class="srfm-submit-wrap"> |
| 518 | <?php echo esc_html( $button_text ); ?> |
| 519 | <div class="srfm-loader"></div> |
| 520 | </div> |
| 521 | </button> |
| 522 | <?php do_action( 'srfm_after_submit_button', $id ); ?> |
| 523 | </div> |
| 524 | </div> |
| 525 | <?php |
| 526 | } |
| 527 | self::common_error_message( 'footer' ); |
| 528 | ?> |
| 529 | </form> |
| 530 | <div class="srfm-single-form srfm-success-box in-page"> |
| 531 | <div aria-live="polite" aria-atomic="true" role="alert" id="srfm-success-message-page-<?php echo esc_attr( Helper::get_string_value( $id ) ); ?>" class="srfm-success-box-description"></div> |
| 532 | </div> |
| 533 | </div> |
| 534 | <?php |
| 535 | return ob_get_clean(); |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Generate HCaptcha script markup |
| 540 | * |
| 541 | * @param string $srfm_hcaptcha_site_key site key. |
| 542 | * @since 1.7.0 |
| 543 | * @return void |
| 544 | */ |
| 545 | public static function get_h_captcha_script( $srfm_hcaptcha_site_key ) { |
| 546 | if ( ! empty( $srfm_hcaptcha_site_key ) ) { |
| 547 | // hCaptcha script. |
| 548 | wp_enqueue_script( 'hcaptcha', 'https://js.hcaptcha.com/1/api.js', [], null, [ 'strategy' => 'defer' ] ); // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion |
| 549 | ?> |
| 550 | <div id="srfm-hcaptcha-sitekey" data-callback="onSuccess" data-error-callback="onHCaptchaError" class="h-captcha" data-sitekey="<?php echo esc_attr( $srfm_hcaptcha_site_key ); ?>"></div> |
| 551 | <?php |
| 552 | } else { |
| 553 | Helper::render_missing_sitekey_error( 'HCaptcha' ); |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Generate Google Recaptcha script markup |
| 559 | * |
| 560 | * @param string $recaptcha_version reCAPTCHA version. |
| 561 | * @param string $google_captcha_site_key site key. |
| 562 | * @since 1.7.0 |
| 563 | * @return void |
| 564 | */ |
| 565 | public static function get_google_captcha_script( $recaptcha_version, $google_captcha_site_key ) { |
| 566 | |
| 567 | if ( empty( $google_captcha_site_key ) ) { |
| 568 | Helper::render_missing_sitekey_error( 'Google reCAPTCHA' ); |
| 569 | return; |
| 570 | } |
| 571 | |
| 572 | if ( 'v2-checkbox' === $recaptcha_version ) { |
| 573 | ?> |
| 574 | <?php |
| 575 | wp_enqueue_script( 'google-recaptcha', 'https://www.google.com/recaptcha/api.js', [], SRFM_VER, true ); |
| 576 | ?> |
| 577 | <div class='g-recaptcha' data-callback="onSuccess" data-error-callback="onGCaptchaV2CheckBoxError" recaptcha-type="<?php echo esc_attr( $recaptcha_version ); ?>" data-sitekey="<?php echo esc_attr( strval( $google_captcha_site_key ) ); ?>" ></div> |
| 578 | <?php } ?> |
| 579 | |
| 580 | <?php if ( 'v2-invisible' === $recaptcha_version ) { ?> |
| 581 | <?php |
| 582 | wp_enqueue_script( 'google-recaptcha-invisible', 'https://www.google.com/recaptcha/api.js?onload=recaptchaCallback&render=explicit', [ SRFM_SLUG . '-form-submit' ], SRFM_VER, true ); |
| 583 | ?> |
| 584 | <div class='g-recaptcha' recaptcha-type="<?php echo esc_attr( $recaptcha_version ); ?>" data-sitekey="<?php echo esc_attr( $google_captcha_site_key ); ?>" data-size="invisible"></div> |
| 585 | <?php } ?> |
| 586 | |
| 587 | <?php if ( 'v3-reCAPTCHA' === $recaptcha_version ) { ?> |
| 588 | <?php |
| 589 | wp_enqueue_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- This is a third-party script, and specifying a version may lead to caching issues. Using null ensures the latest version is always loaded. |
| 590 | 'srfm-google-recaptchaV3', |
| 591 | 'https://www.google.com/recaptcha/api.js?render=' . $google_captcha_site_key, |
| 592 | [], |
| 593 | null, |
| 594 | true |
| 595 | ); |
| 596 | ?> |
| 597 | <?php |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Generate Cloudflare Turnstile script markup |
| 603 | * |
| 604 | * @param string $srfm_cf_appearance_mode appearance mode. |
| 605 | * @param string $srfm_cf_turnstile_site_key site key. |
| 606 | * @since 1.7.0 |
| 607 | * @return void |
| 608 | */ |
| 609 | public static function get_cf_turnstile_script( $srfm_cf_appearance_mode, $srfm_cf_turnstile_site_key ) { |
| 610 | if ( ! empty( $srfm_cf_turnstile_site_key ) ) { |
| 611 | // Cloudflare Turnstile script. |
| 612 | wp_enqueue_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion -- Third-party script; version not under our control. |
| 613 | SRFM_SLUG . '-cf-turnstile', |
| 614 | 'https://challenges.cloudflare.com/turnstile/v0/api.js', |
| 615 | [], |
| 616 | null, |
| 617 | [ |
| 618 | false, |
| 619 | 'defer' => true, |
| 620 | ] |
| 621 | ); |
| 622 | ?> |
| 623 | <!-- The callback methods below are available on frontend.js. onTurnstileError displays and error in place of recaptcha dialog. --> |
| 624 | <div id="srfm-cf-sitekey" class="cf-turnstile" data-callback="onSuccess" data-error-callback="onTurnstileError" data-theme="<?php echo esc_attr( $srfm_cf_appearance_mode ); ?>" data-sitekey="<?php echo esc_attr( $srfm_cf_turnstile_site_key ); ?>"></div> |
| 625 | <?php |
| 626 | } else { |
| 627 | Helper::render_missing_sitekey_error( 'Turnstile' ); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | /** |
| 632 | * Generate common error message markup |
| 633 | * |
| 634 | * @param string $position position of the error message. |
| 635 | * @since 1.5.0 |
| 636 | * @return void |
| 637 | */ |
| 638 | public static function common_error_message( $position = 'footer' ) { |
| 639 | $icon = Helper::fetch_svg( 'info_circle', '', 'aria-hidden="true"' ); |
| 640 | $classes = "srfm-common-error-message srfm-error-message srfm-{$position}-error"; |
| 641 | ?> |
| 642 | <p id="srfm-error-message" class="<?php echo esc_attr( $classes ); ?>" hidden="true"><?php echo wp_kses( $icon, Helper::$allowed_tags_svg ); ?><span class="srfm-error-content"><?php echo esc_html__( 'There was an error trying to submit your form. Please try again.', 'sureforms' ); ?></span></p> |
| 643 | <?php |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * Generate form confirmation markup |
| 648 | * |
| 649 | * @param array<mixed> $form_data contains form data. |
| 650 | * @param array<mixed> $submission_data contains submission data. |
| 651 | * @since 0.0.3 |
| 652 | * @return string|false |
| 653 | */ |
| 654 | public static function get_confirmation_markup( $form_data = [], $submission_data = [] ) { |
| 655 | |
| 656 | $confirmation_message = ''; |
| 657 | |
| 658 | if ( empty( $form_data ) ) { |
| 659 | return $confirmation_message; |
| 660 | } |
| 661 | |
| 662 | $form_confirmation = isset( $form_data['form-id'] ) ? |
| 663 | get_post_meta( Helper::get_integer_value( $form_data['form-id'] ), '_srfm_form_confirmation' ) : null; |
| 664 | |
| 665 | if ( ! is_array( $form_confirmation ) ) { |
| 666 | return $confirmation_message; |
| 667 | } |
| 668 | |
| 669 | $confirmation_data = is_array( $form_confirmation[0] ) && isset( $form_confirmation[0][0] ) ? $form_confirmation[0][0] : null; |
| 670 | |
| 671 | if ( is_array( $form_confirmation ) && isset( $confirmation_data['message'] ) && is_string( $confirmation_data['message'] ) ) { |
| 672 | $confirmation_message = $confirmation_data['message']; |
| 673 | } |
| 674 | if ( empty( $submission_data ) ) { |
| 675 | return $confirmation_message; |
| 676 | } |
| 677 | $smart_tags = new Smart_Tags(); |
| 678 | $confirmation_message = $smart_tags->process_smart_tags( $confirmation_message, $submission_data, $form_data ); |
| 679 | |
| 680 | $markup = Helper::strip_js_attributes( apply_filters( 'srfm_after_submit_confirmation_message', $confirmation_message ) ); |
| 681 | |
| 682 | if ( false !== strpos( $markup, 'src="image/svg+xml;base64' ) ) { |
| 683 | // Handle Form Confirmation SVGs separately. We have planned to improve it in the future replacing it with image URL. |
| 684 | $normalized_string = preg_replace( '/src="image\/svg\+xml;base64/', 'src="data:image/svg+xml;base64', $markup ); |
| 685 | |
| 686 | if ( is_string( $normalized_string ) ) { |
| 687 | $markup = $normalized_string; |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | return $markup; |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * Get redirect url for form incase of different page or custom url is selected. |
| 696 | * |
| 697 | * @param array<mixed> $form_data contains form data. |
| 698 | * @param array<mixed> $submission_data contains submission data. |
| 699 | * @since 1.0.2 |
| 700 | * @return string|false |
| 701 | */ |
| 702 | public static function get_redirect_url( $form_data = [], $submission_data = [] ) { |
| 703 | $redirect_url = ''; |
| 704 | |
| 705 | if ( empty( $form_data ) ) { |
| 706 | return $redirect_url; |
| 707 | } |
| 708 | |
| 709 | $form_confirmation = isset( $form_data['form-id'] ) ? |
| 710 | get_post_meta( Helper::get_integer_value( $form_data['form-id'] ), '_srfm_form_confirmation' ) : null; |
| 711 | |
| 712 | if ( ! is_array( $form_confirmation ) ) { |
| 713 | return $redirect_url; |
| 714 | } |
| 715 | |
| 716 | $confirmation_data = is_array( $form_confirmation[0] ) && isset( $form_confirmation[0][0] ) ? $form_confirmation[0][0] : null; |
| 717 | |
| 718 | $page_url = $confirmation_data['page_url'] ?? ''; |
| 719 | $custom_url = $confirmation_data['custom_url'] ?? ''; |
| 720 | $confirmation_type = $confirmation_data['confirmation_type'] ?? ''; |
| 721 | if ( 'different page' === $confirmation_type ) { |
| 722 | $redirect_url = esc_url( $page_url ); |
| 723 | } elseif ( 'custom url' === $confirmation_type ) { |
| 724 | $redirect_url = esc_url( $custom_url ); |
| 725 | } |
| 726 | |
| 727 | if ( empty( $redirect_url ) ) { |
| 728 | return $redirect_url; |
| 729 | } |
| 730 | |
| 731 | if ( empty( $confirmation_data['enable_query_params'] ) || true !== $confirmation_data['enable_query_params'] ) { |
| 732 | return $redirect_url; |
| 733 | } |
| 734 | |
| 735 | if ( empty( $confirmation_data['query_params'] ) && ! is_array( $confirmation_data['query_params'] ) ) { |
| 736 | return $redirect_url; |
| 737 | } |
| 738 | |
| 739 | $query_params = []; |
| 740 | foreach ( $confirmation_data['query_params'] as $params ) { |
| 741 | if ( is_array( $params ) && ! empty( array_keys( $params ) ) && ! empty( array_values( $params ) ) ) { |
| 742 | $query_params[ esc_attr( array_keys( $params )[0] ) ] = esc_attr( array_values( $params )[0] ); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | $redirect_url = add_query_arg( $query_params, $redirect_url ); |
| 747 | |
| 748 | if ( ! empty( $submission_data ) ) { |
| 749 | $smart_tags = new Smart_Tags(); |
| 750 | // Adding upload_format_type = 'raw' to retrieve urls as comma separated values. |
| 751 | $form_data['upload_format_type'] = 'raw'; |
| 752 | $redirect_url = html_entity_decode( $smart_tags->process_smart_tags( $redirect_url, $submission_data, $form_data ) ); |
| 753 | } |
| 754 | |
| 755 | return apply_filters( 'srfm_after_submit_redirect_url', $redirect_url ); |
| 756 | } |
| 757 | } |
| 758 |