@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | */ |
26 | 26 | public function __construct() { |
27 | 27 | // hook the HTML ID string find & replace functionality |
28 | - add_filter( 'gform_get_form_filter', array( $this, 'gform_get_form_filter' ), 10, 2 ); |
|
28 | + add_filter('gform_get_form_filter', array($this, 'gform_get_form_filter'), 10, 2); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -39,10 +39,10 @@ discard block |
||
39 | 39 | * @param array $form Array with the form settings. |
40 | 40 | * @return string $form_string The modified form HTML string. |
41 | 41 | */ |
42 | - public function gform_get_form_filter( $form_string, $form ) { |
|
42 | + public function gform_get_form_filter($form_string, $form) { |
|
43 | 43 | // if form has been submitted, use the submitted ID, otherwise generate a new unique ID |
44 | - if ( isset( $_POST['gform_random_id'] ) ) { |
|
45 | - $random_id = absint( $_POST['gform_random_id'] ); // Input var okay. |
|
44 | + if (isset($_POST['gform_random_id'])) { |
|
45 | + $random_id = absint($_POST['gform_random_id']); // Input var okay. |
|
46 | 46 | } else { |
47 | 47 | $random_id = mt_rand(); |
48 | 48 | } |
@@ -52,58 +52,58 @@ discard block |
||
52 | 52 | |
53 | 53 | // define all occurences of the original form ID that wont hurt the form input |
54 | 54 | $strings = array( |
55 | - ' gform_wrapper ' => ' gform_wrapper gform_wrapper_original_id_' . $form['id'] . ' ', |
|
56 | - "for='choice_" => "for='choice_" . $random_id . '_', |
|
57 | - "id='label_" => "id='label_" . $random_id . '_', |
|
58 | - "'gform_wrapper_" . $form['id'] . "'" => "'gform_wrapper_" . $random_id . "'", |
|
59 | - "'gf_" . $form['id'] . "'" => "'gf_" . $random_id . "'", |
|
60 | - "'gform_" . $form['id'] . "'" => "'gform_" . $random_id . "'", |
|
61 | - "'gform_ajax_frame_" . $form['id'] . "'" => "'gform_ajax_frame_" . $random_id . "'", |
|
62 | - '#gf_' . $form['id'] . "'" => '#gf_' . $random_id . "'", |
|
63 | - "'gform_fields_" . $form['id'] . "'" => "'gform_fields_" . $random_id . "'", |
|
64 | - "id='field_" . $form['id'] . '_' => "id='field_" . $random_id . '_', |
|
65 | - "for='input_" . $form['id'] . '_' => "for='input_" . $random_id . '_', |
|
66 | - "id='input_" . $form['id'] . '_' => "id='input_" . $random_id . '_', |
|
67 | - "id='choice_" . $form['id'] . '_' => "id='choice_" . $random_id . '_', |
|
68 | - "'gform_submit_button_" . $form['id'] . "'" => "'gform_submit_button_" . $random_id . "'", |
|
69 | - '"gf_submitting_' . $form['id'] . '"' => '"gf_submitting_' . $random_id . '"', |
|
70 | - "'gf_submitting_" . $form['id'] . "'" => "'gf_submitting_" . $random_id . "'", |
|
71 | - '#gform_ajax_frame_' . $form['id'] => '#gform_ajax_frame_' . $random_id, |
|
72 | - '#gform_wrapper_' . $form['id'] => '#gform_wrapper_' . $random_id, |
|
73 | - '#gform_' . $form['id'] => '#gform_' . $random_id, |
|
74 | - "trigger('gform_post_render', [" . $form['id'] => "trigger('gform_post_render', [" . $random_id, |
|
75 | - 'gformInitSpinner( ' . $form['id'] . ',' => 'gformInitSpinner( ' . $random_id . ',', |
|
76 | - "trigger('gform_page_loaded', [" . $form['id'] => "trigger('gform_page_loaded', [" . $random_id, |
|
77 | - "'gform_confirmation_loaded', [" . $form['id'] . ']' => "'gform_confirmation_loaded', [" . $random_id . ']', |
|
78 | - 'gf_apply_rules(' . $form['id'] . ',' => 'gf_apply_rules(' . $random_id . ',', |
|
79 | - 'gform_confirmation_wrapper_' . $form['id'] => 'gform_confirmation_wrapper_' . $random_id, |
|
80 | - 'gforms_confirmation_message_' . $form['id'] => 'gforms_confirmation_message_' . $random_id, |
|
81 | - 'gform_confirmation_message_' . $form['id'] => 'gform_confirmation_message_' . $random_id, |
|
82 | - 'if(formId == ' . $form['id'] . ')' => 'if(formId == ' . $random_id . ')', |
|
83 | - "window['gf_form_conditional_logic'][" . $form['id'] . ']' => "window['gf_form_conditional_logic'][" . $random_id . ']', |
|
84 | - "trigger('gform_post_conditional_logic', [" . $form['id'] . ',' => "trigger('gform_post_conditional_logic', [" . $random_id . ',', |
|
85 | - 'gformShowPasswordStrength("input_' . $form['id'] . '_' => 'gformShowPasswordStrength("input_' . $random_id . '_', |
|
86 | - "gformInitChosenFields('#input_" . $form['id'] . '_' => "gformInitChosenFields('#input_" . $random_id . '_', |
|
87 | - "jQuery('#input_" . $form['id'] . '_' => "jQuery('#input_" . $random_id . '_', |
|
88 | - 'gforms_calendar_icon_input_' . $form['id'] . '_' => 'gforms_calendar_icon_input_' . $random_id . '_', |
|
89 | - "id='ginput_base_price_" . $form['id'] . '_' => "id='ginput_base_price_" . $random_id . '_', |
|
90 | - "id='ginput_quantity_" . $form['id'] . '_' => "id='ginput_quantity_" . $random_id . '_', |
|
91 | - 'gfield_price_' . $form['id'] . '_' => 'gfield_price_' . $random_id . '_', |
|
92 | - 'gfield_quantity_' . $form['id'] . '_' => 'gfield_quantity_' . $random_id . '_', |
|
93 | - 'gfield_product_' . $form['id'] . '_' => 'gfield_product_' . $random_id . '_', |
|
94 | - 'ginput_total_' . $form['id'] => 'ginput_total_' . $random_id, |
|
95 | - 'GFCalc(' . $form['id'] . ',' => 'GFCalc(' . $random_id . ',', |
|
96 | - 'gf_global["number_formats"][' . $form['id'] . ']' => 'gf_global["number_formats"][' . $random_id . ']', |
|
97 | - 'gform_next_button_' . $form['id'] . '_' => 'gform_next_button_' . $random_id . '_', |
|
98 | - $hidden_field => "<input type='hidden' name='gform_random_id' value='" . $random_id . "' />" . $hidden_field, |
|
55 | + ' gform_wrapper ' => ' gform_wrapper gform_wrapper_original_id_'.$form['id'].' ', |
|
56 | + "for='choice_" => "for='choice_".$random_id.'_', |
|
57 | + "id='label_" => "id='label_".$random_id.'_', |
|
58 | + "'gform_wrapper_".$form['id']."'" => "'gform_wrapper_".$random_id."'", |
|
59 | + "'gf_".$form['id']."'" => "'gf_".$random_id."'", |
|
60 | + "'gform_".$form['id']."'" => "'gform_".$random_id."'", |
|
61 | + "'gform_ajax_frame_".$form['id']."'" => "'gform_ajax_frame_".$random_id."'", |
|
62 | + '#gf_'.$form['id']."'" => '#gf_'.$random_id."'", |
|
63 | + "'gform_fields_".$form['id']."'" => "'gform_fields_".$random_id."'", |
|
64 | + "id='field_".$form['id'].'_' => "id='field_".$random_id.'_', |
|
65 | + "for='input_".$form['id'].'_' => "for='input_".$random_id.'_', |
|
66 | + "id='input_".$form['id'].'_' => "id='input_".$random_id.'_', |
|
67 | + "id='choice_".$form['id'].'_' => "id='choice_".$random_id.'_', |
|
68 | + "'gform_submit_button_".$form['id']."'" => "'gform_submit_button_".$random_id."'", |
|
69 | + '"gf_submitting_'.$form['id'].'"' => '"gf_submitting_'.$random_id.'"', |
|
70 | + "'gf_submitting_".$form['id']."'" => "'gf_submitting_".$random_id."'", |
|
71 | + '#gform_ajax_frame_'.$form['id'] => '#gform_ajax_frame_'.$random_id, |
|
72 | + '#gform_wrapper_'.$form['id'] => '#gform_wrapper_'.$random_id, |
|
73 | + '#gform_'.$form['id'] => '#gform_'.$random_id, |
|
74 | + "trigger('gform_post_render', [".$form['id'] => "trigger('gform_post_render', [".$random_id, |
|
75 | + 'gformInitSpinner( '.$form['id'].',' => 'gformInitSpinner( '.$random_id.',', |
|
76 | + "trigger('gform_page_loaded', [".$form['id'] => "trigger('gform_page_loaded', [".$random_id, |
|
77 | + "'gform_confirmation_loaded', [".$form['id'].']' => "'gform_confirmation_loaded', [".$random_id.']', |
|
78 | + 'gf_apply_rules('.$form['id'].',' => 'gf_apply_rules('.$random_id.',', |
|
79 | + 'gform_confirmation_wrapper_'.$form['id'] => 'gform_confirmation_wrapper_'.$random_id, |
|
80 | + 'gforms_confirmation_message_'.$form['id'] => 'gforms_confirmation_message_'.$random_id, |
|
81 | + 'gform_confirmation_message_'.$form['id'] => 'gform_confirmation_message_'.$random_id, |
|
82 | + 'if(formId == '.$form['id'].')' => 'if(formId == '.$random_id.')', |
|
83 | + "window['gf_form_conditional_logic'][".$form['id'].']' => "window['gf_form_conditional_logic'][".$random_id.']', |
|
84 | + "trigger('gform_post_conditional_logic', [".$form['id'].',' => "trigger('gform_post_conditional_logic', [".$random_id.',', |
|
85 | + 'gformShowPasswordStrength("input_'.$form['id'].'_' => 'gformShowPasswordStrength("input_'.$random_id.'_', |
|
86 | + "gformInitChosenFields('#input_".$form['id'].'_' => "gformInitChosenFields('#input_".$random_id.'_', |
|
87 | + "jQuery('#input_".$form['id'].'_' => "jQuery('#input_".$random_id.'_', |
|
88 | + 'gforms_calendar_icon_input_'.$form['id'].'_' => 'gforms_calendar_icon_input_'.$random_id.'_', |
|
89 | + "id='ginput_base_price_".$form['id'].'_' => "id='ginput_base_price_".$random_id.'_', |
|
90 | + "id='ginput_quantity_".$form['id'].'_' => "id='ginput_quantity_".$random_id.'_', |
|
91 | + 'gfield_price_'.$form['id'].'_' => 'gfield_price_'.$random_id.'_', |
|
92 | + 'gfield_quantity_'.$form['id'].'_' => 'gfield_quantity_'.$random_id.'_', |
|
93 | + 'gfield_product_'.$form['id'].'_' => 'gfield_product_'.$random_id.'_', |
|
94 | + 'ginput_total_'.$form['id'] => 'ginput_total_'.$random_id, |
|
95 | + 'GFCalc('.$form['id'].',' => 'GFCalc('.$random_id.',', |
|
96 | + 'gf_global["number_formats"]['.$form['id'].']' => 'gf_global["number_formats"]['.$random_id.']', |
|
97 | + 'gform_next_button_'.$form['id'].'_' => 'gform_next_button_'.$random_id.'_', |
|
98 | + $hidden_field => "<input type='hidden' name='gform_random_id' value='".$random_id."' />".$hidden_field, |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | // allow addons & plugins to add additional find & replace strings |
102 | - $strings = apply_filters( 'gform_multiple_instances_strings', $strings ); |
|
102 | + $strings = apply_filters('gform_multiple_instances_strings', $strings); |
|
103 | 103 | |
104 | 104 | // replace all occurences with the new unique ID |
105 | - foreach ( $strings as $find => $replace ) { |
|
106 | - $form_string = str_replace( $find, $replace, $form_string ); |
|
105 | + foreach ($strings as $find => $replace) { |
|
106 | + $form_string = str_replace($find, $replace, $form_string); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | return $form_string; |