Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions gravityforms-multiple-form-instances.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* The main plugin class.
*/
class Gravity_Forms_Multiple_Form_Instances {
/**
* array $previous_forms track the previous forms so we know if we need to change the id
*/
protected $previous_forms = [];

/**
* Constructor.
Expand Down Expand Up @@ -43,6 +47,12 @@ public function gform_get_form_filter( $form_string, $form ) {
// if form has been submitted, use the submitted ID, otherwise generate a new unique ID
if ( isset( $_POST['gform_random_id'] ) ) {
$random_id = absint( $_POST['gform_random_id'] ); // Input var okay.
} elseif ( !in_array($form['id'], $this->previous_forms) ) {
// if this is the first time we are seeing this form id then don't change the id
// this allows for add-ons like Stripe to still work since their JS depends on
// the form id.
$random_id = $form['id'];
array_push($this->previous_forms, $form['id']);
} else {
$random_id = mt_rand();
}
Expand Down Expand Up @@ -95,6 +105,8 @@ public function gform_get_form_filter( $form_string, $form ) {
'GFCalc(' . $form['id'] . ',' => 'GFCalc(' . $random_id . ',',
'gf_global["number_formats"][' . $form['id'] . ']' => 'gf_global["number_formats"][' . $random_id . ']',
'gform_next_button_' . $form['id'] . '_' => 'gform_next_button_' . $random_id . '_',
'gform_source_page_number_' . $form['id'] => 'gform_source_page_number_' . $random_id,
'gform_target_page_number_' . $form['id'] => 'gform_target_page_number_' . $random_id,
$hidden_field => "<input type='hidden' name='gform_random_id' value='" . $random_id . "' />" . $hidden_field,
);

Expand Down