Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaks forms with conditional logic #21

Open
eagle-r opened this issue Dec 5, 2016 · 16 comments
Open

Breaks forms with conditional logic #21

eagle-r opened this issue Dec 5, 2016 · 16 comments

Comments

@eagle-r
Copy link

eagle-r commented Dec 5, 2016

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

@corneliusio
Copy link

This. ☝️

@carlouni
Copy link

carlouni commented Mar 1, 2017

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

@tyxla
Copy link
Owner

tyxla commented Mar 1, 2017

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

@bbarnwell
Copy link

Any progress on this?

@tyxla
Copy link
Owner

tyxla commented Apr 13, 2017

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

@bbarnwell
Copy link

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
Copy link

bbarnwell commented Apr 21, 2017

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;

@tyxla
Copy link
Owner

tyxla commented Apr 24, 2017

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.

@bbarnwell
Copy link

Much better! Thanks!

@leepeterson
Copy link

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% :)

@tyxla
Copy link
Owner

tyxla commented May 2, 2017

@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.

@PaulBRobinson
Copy link

PaulBRobinson commented Aug 22, 2017

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.

@amimeinc
Copy link

@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!

@PaulBRobinson
Copy link

@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.

@mellodave
Copy link

mellodave commented Jun 8, 2018

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

@tyxla
Copy link
Owner

tyxla commented Jun 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants