Gravity-Forms-Multiple-Form-Instances icon indicating copy to clipboard operation
Gravity-Forms-Multiple-Form-Instances copied to clipboard

Breaks forms with conditional logic

Open eagle-r opened this issue 8 years ago • 16 comments

It breaks a form that has conditional logic in it for GravityForms 2.x

eagle-r avatar Dec 05 '16 05:12 eagle-r

This. ☝️

corneliusio avatar Feb 06 '17 22:02 corneliusio

Have the same issue with the new version of GF. Any plans for fixing this issue?

carlouni avatar Mar 01 '17 01:03 carlouni

Not really on my priority list, but I intend to spend some time to investigate and fix it soon.

tyxla avatar Mar 01 '17 07:03 tyxla

Any progress on this?

bbarnwell avatar Apr 13 '17 16:04 bbarnwell

Haven't had time to have a look. Any contributions are highly appreciated! :+1:

tyxla avatar Apr 13 '17 18:04 tyxla

Fair enough. I may just try to disable the find/replace id functionality on affected pages, since for us there’s just one page and form affected right now – and, the form that this plugin was installed for is not on the same page. A temp workaround for now.

bbarnwell avatar Apr 21 '17 14:04 bbarnwell

Hey folks,

In case this helps anyone, for now I've just added an if statement to exclude the functionality on the one page where it was an issue. (There's three in my code below for dev, test and prod).

Cheers, Bill

public function gform_get_form_filter( $form_string, $form ) { if ( is_page(20582) || is_page(20676) || is_page(34373) ){ // do next execute if page - dev, dev2 and prod // do nothing } else {

and close the if statement adding another bracket before the return...

} } return $form_string;

bbarnwell avatar Apr 21 '17 20:04 bbarnwell

If that is the case, you can easily disable the plugin for these pages only by simply unhooking the main filter on these pages, like this:

add_action( 'wp', 'my_remove_gravity_forms_multiple_instances' );
function my_remove_gravity_forms_multiple_instances() {
	if ( is_page( 20582 ) || is_page( 20676 ) || is_page( 34373 ) ) {
		global $gravity_forms_multiple_form_instances;
		remove_filter( 'gform_get_form_filter', array( $gravity_forms_multiple_form_instances, 'gform_get_form_filter' ), 10, 2 );
	}
}

@bbarnwell if you add this as a custom plugin or custom code in your theme, you won't have to modify this plugin; and you will be able to update it when new versions are released.

tyxla avatar Apr 24 '17 06:04 tyxla

Much better! Thanks!

bbarnwell avatar Apr 26 '17 13:04 bbarnwell

Any contributions are highly appreciated!

@tyxla Which type of contributions would help solve this issue? Hit me up here, via email, wherever and that contribution will be made instantly! Rocketgenius themselves should have had the root of this issue addressed years ago. Can't tell you how appreciative we all are for this add-on you've provided for free! Time to get it working 100% :)

leepeterson avatar Apr 29 '17 17:04 leepeterson

@leepeterson I'm happy you find the plugin helpful :)

Basically, there are some edge cases with the more complex functionality like conditional logic, or with some of the addons that requires additional love in order to work with multiple forms on the same page. I haven't had the time myself to play with it, but it shouldn't be a big deal to address some of those bigger pain points like the conditional logic. There is also an issue with the multiple file upload field: #20.

It's in my plans to work on the plugin the next months, but I'm not sure when I'll be able to spare some time. In the meantime, any PRs that fix the known issues are highly appreciated, and I will try to provide as much support as I can, in order to land them in the plugin.

tyxla avatar May 02 '17 11:05 tyxla

I've been reading through this as I've just ran into this issue on a bit of work I'm doing. I'm sure this doesn't fix it completely but changing:

$strings = array(
    ...
    "id='choice_" => "id='choice_" . $random_id . '_',
    ...
);

to:

$strings = array(
    ...
    "id='choice_" . $form['id'] => "id='choice_" . $random_id,
    ...
);

Seems to get conditionals working again. At least for Checkboxes and radios. Does that help anyone at all?

Edit: fixed the code formatting.

PaulBRobinson avatar Aug 22 '17 09:08 PaulBRobinson

@Nabesaka Thank you so much! You definitely helped me!

I had previously done a fix I found on the Wordpress support page for the plugin but all that did was remove the plugin from all pages except the couple that had multiple forms. Then the conditional logic just wouldn't work on those pages but at least the forms would show. With your fix I can run the plugin like intended and my conditional checkboxes work.

My hero!

amimeinc avatar Sep 29 '17 20:09 amimeinc

@amimeinc Glad it was helpful. As I mentioned I'm not sure if it is a complete fix or anything but it seems to do the job for the moment at least.

PaulBRobinson avatar Oct 02 '17 12:10 PaulBRobinson

Not sure if this is exactly the issue being discussed here, but I spent several hours today tracking down/fixing something similar, so I wanted to share.

The bug I found is caused by having a page containing multiple non-ajax forms, each with conditional logic. If one of the form submits but returns validation errors, then the conditional logic breaks.

This is happening because, when the validation error takes place and this plugin was called as all the forms on the page re-rendered, it was setting the same $_POST['gform_random_id'] for all of the forms on the page, not just for the one that was failing. This resulted in, among other things, conditional logic for all but the last form on the page, to break (because window['gf_form_conditional_logic'] was being overwritten by every form).

I fixed this by trying to detect when a $_POST['gform_random_id'] takes place, and only re-using that id for the form that originally had it. All other forms get new random ids.

The only use case that I could find that is still problematic is when there are more than one form of the same type on the page, and one is set to submit via ajax, and the other is not. This doesn't work - all forms of the same type need to use the same submission methods (ajax, or non-ajax). Forms of different types, however, can be set to have different submission methods, without a problem.

Plugin code with my updates is attached.

gravityforms-multiple-form-instances.txt

mellodave avatar Jun 08 '18 20:06 mellodave

@mellodave thanks for that! PRs are welcome, in case you'd like to land a fix in the plugin 😉

tyxla avatar Jun 11 '18 10:06 tyxla