These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Plugin Name: Gravity Forms: Multiple Form Instances |
||
4 | * Description: Allows multiple instances of the same form to be run on a single page when using AJAX. |
||
5 | * Author: tyxla |
||
6 | * Author URI: http://marinatanasov.com/ |
||
7 | * Plugin URI: https://github.com/tyxla/Gravity-Forms-Multiple-Form-Instances |
||
8 | * Version: 1.0.15 |
||
9 | * License: GPL2 |
||
10 | * Requires at least: 3.0.1 |
||
11 | * Tested up to: 4.4.1 |
||
12 | */ |
||
13 | |||
14 | /** |
||
15 | * The main plugin class. |
||
16 | */ |
||
17 | class Gravity_Forms_Multiple_Form_Instances { |
||
18 | |||
19 | /** |
||
20 | * Constructor. |
||
21 | * |
||
22 | * Used to initialize the plugin and hook the related functionality. |
||
23 | * |
||
24 | * @access public |
||
25 | */ |
||
26 | 1 | public function __construct() { |
|
27 | // hook the HTML ID string find & replace functionality |
||
28 | 1 | add_filter( 'gform_get_form_filter', array( $this, 'gform_get_form_filter' ), 10, 2 ); |
|
29 | 1 | } |
|
30 | |||
31 | /** |
||
32 | * Replaces all occurences of the form ID with a new, unique ID. |
||
33 | * |
||
34 | * This is where the magic happens. |
||
35 | * |
||
36 | * @access public |
||
37 | * |
||
38 | * @param string $form_string The form HTML string. |
||
39 | * @param array $form Array with the form settings. |
||
40 | * @return string $form_string The modified form HTML string. |
||
41 | */ |
||
42 | public function gform_get_form_filter( $form_string, $form ) { |
||
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. |
||
46 | } else { |
||
47 | $random_id = mt_rand(); |
||
48 | } |
||
49 | |||
50 | // this is where we keep our unique ID |
||
51 | $hidden_field = "<input type='hidden' name='gform_field_values'"; |
||
52 | |||
53 | // define all occurences of the original form ID that wont hurt the form input |
||
54 | $strings = array( |
||
55 | "for='choice_" => "for='choice_" . $random_id . '_', |
||
56 | "id='choice_" => "id='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 . "'", |
||
0 ignored issues
–
show
|
|||
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 | "'gform_submit_button_" . $form['id'] . "'" => "'gform_submit_button_" . $random_id . "'", |
||
68 | '"gf_submitting_' . $form['id'] . '"' => '"gf_submitting_' . $random_id . '"', |
||
69 | "'gf_submitting_" . $form['id'] . "'" => "'gf_submitting_" . $random_id . "'", |
||
70 | "#gform_ajax_frame_" . $form['id'] => "#gform_ajax_frame_" . $random_id, |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
#gform_ajax_frame_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
71 | "#gform_wrapper_" . $form['id'] => "#gform_wrapper_" . $random_id, |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
#gform_wrapper_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
72 | "#gform_" . $form['id'] => "#gform_" . $random_id, |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
#gform_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
73 | "trigger('gform_post_render', [" . $form['id'] => "trigger('gform_post_render', [" . $random_id, |
||
74 | "gformInitSpinner( " . $form['id'] . "," => "gformInitSpinner( " . $random_id . ",", |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
gformInitSpinner( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
Coding Style
Comprehensibility
introduced
by
The string literal
, does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
75 | "trigger('gform_page_loaded', [" . $form['id'] => "trigger('gform_page_loaded', [" . $random_id, |
||
76 | "'gform_confirmation_loaded', [" . $form['id'] . "]" => "'gform_confirmation_loaded', [" . $random_id . "]", |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
] does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
77 | 'gf_apply_rules(' . $form['id'] . ',' => 'gf_apply_rules(' . $random_id . ',', |
||
78 | 'gform_confirmation_wrapper_' . $form['id'] => 'gform_confirmation_wrapper_' . $random_id, |
||
79 | 'gforms_confirmation_message_' . $form['id'] => 'gform_confirmation_wrapper_' . $random_id, |
||
80 | 'gform_confirmation_message_' . $form['id'] => 'gform_confirmation_message_' . $random_id, |
||
81 | 'if(formId == ' . $form['id'] . ')' => 'if(formId == ' . $random_id . ')', |
||
82 | "window['gf_form_conditional_logic'][" . $form['id'] . "]" => "window['gf_form_conditional_logic'][" . $random_id . "]", |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
] does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
83 | "trigger('gform_post_conditional_logic', [" . $form['id'] . "," => "trigger('gform_post_conditional_logic', [" . $random_id . ",", |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
, does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
84 | 'gformShowPasswordStrength("input_' . $form['id'] . '_' => 'gformShowPasswordStrength("input_' . $random_id . '_', |
||
85 | "gformInitChosenFields('#input_" . $form['id'] . '_' => "gformInitChosenFields('#input_" . $random_id . '_', |
||
86 | "jQuery('#input_" . $form['id'] . '_' => "jQuery('#input_" . $random_id . '_', |
||
87 | 'gforms_calendar_icon_input_' . $form['id'] . '_' => 'gforms_calendar_icon_input_' . $random_id . '_', |
||
88 | "id='ginput_base_price_" . $form['id'] . '_' => "id='ginput_base_price_" . $random_id . '_', |
||
89 | "id='ginput_quantity_" . $form['id'] . '_' => "id='ginput_quantity_" . $random_id . '_', |
||
90 | "gfield_price_" . $form['id'] . '_' => "gfield_price_" . $random_id . '_', |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
gfield_price_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
91 | "gfield_quantity_" . $form['id'] . '_' => "gfield_quantity_" . $random_id . '_', |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
gfield_quantity_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
92 | "gfield_product_" . $form['id'] . '_' => "gfield_product_" . $random_id . '_', |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
gfield_product_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
93 | "ginput_total_" . $form['id'] => "ginput_total_" . $random_id, |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
ginput_total_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
94 | "GFCalc(" . $form['id'] . "," => "GFCalc(" . $random_id . ",", |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
GFCalc( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
Coding Style
Comprehensibility
introduced
by
The string literal
, does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
95 | 'gf_global["number_formats"][' . $form['id'] . ']' => 'gf_global["number_formats"][' . $random_id . ']', |
||
96 | "gform_next_button_" . $form['id'] . '_' => "gform_next_button_" . $random_id . '_', |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
gform_next_button_ does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
97 | $hidden_field => "<input type='hidden' name='gform_random_id' value='" . $random_id . "' />" . $hidden_field, |
||
98 | ); |
||
99 | |||
100 | // allow addons & plugins to add additional find & replace strings |
||
101 | $strings = apply_filters( 'gform_multiple_instances_strings', $strings ); |
||
102 | |||
103 | // replace all occurences with the new unique ID |
||
104 | foreach ( $strings as $find => $replace ) { |
||
105 | $form_string = str_replace( $find, $replace, $form_string ); |
||
106 | } |
||
107 | |||
108 | return $form_string; |
||
109 | } |
||
110 | |||
111 | } |
||
112 | |||
113 | // initialize the plugin |
||
114 | global $gravity_forms_multiple_form_instances; |
||
115 | $gravity_forms_multiple_form_instances = new Gravity_Forms_Multiple_Form_Instances(); |
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.