Skip Navigation

[Resolved] Conditional output of Forms broken with Optimization Plugin

This thread is resolved. Here is a description of the problem and solution.

Problem:
When I optimize my scripts with a plugin like Autoptimize, my Forms Conditionals stop working.

Solution:
You need to exclude some scripts from optimization

Relevant Documentation:
https://toolset.com/faq/how-to-use-optimization-plugins-with-toolset/

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 10 replies, has 2 voices.

Last updated by Beda 5 years, 7 months ago.

Assigned support staff: Beda.

Author
Posts
#535186

PZ

Hello, I have a problem with conditional display of my fields.

It seems simple in the tutorial and I do everything as shown, step by step, but my conditional fields don't show up. When I set a condition to them they become hidden but they don't display when I choose the right option in the previous fields. Why? Is it a matter of some settings that I missed?

This is the form I am working on:
hidden link

As you can see there is number "3" missing, i set a condition to it. The thing is that it should display when the second option ("części samochodowe") in the previous field is chosen. It doesn't happen.

It looks like this in CRED form:

[credform class='cred-form cred-keep-original']

	[cred_field field='form_messages' value='' class='alert alert-warning']

	<div class="form-group">
		<label>1. Wybierz opcję: kupno lub sprzedaż</label>
		[cred_field field='wybierz-opcje-kupno-lub-sprzedaz' post='ogloszenie' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>2. Wybierz rodzaj ogłoszenia</label>
		[cred_field field='wybierz-rodzaj-ogloszenia-1' post='ogloszenie' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

[cred_show_group if="($(wybierz-rodzaj-ogloszenia-1) eq  '2' )"  mode='fade-slide']
<div class="form-group">
		<label>3. Wybierz rodzaj części</label>
		[cred_field field='3-wybierz-rodzaj-czesci' post='ogloszenie' value='' urlparam='' class='form-control' output='bootstrap']
	</div>
[/cred_show_group]

	<div class="form-group">
		<label>4. Opis ogłoszenia</label>
		[cred_field field='4-opis-ogloszenia' post='ogloszenie' value='' urlparam='' output='bootstrap']
	</div>

	<div class="form-group">
		<label>5. Galeria ogłoszenia</label>
		[cred_field field='galeria-ogloszenia' post='ogloszenie' value='' urlparam='' output='bootstrap']
	</div>

	<div class="form-group">
		<label>6. Cena</label>
		[cred_field field='6-cena' post='ogloszenie' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>7. Telefon kontaktowy</label>
		[cred_field field='7-telefon-kontaktowy' post='ogloszenie' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

	<div class="form-group">
		<label>8. Adres e-mail</label>
		[cred_field field='8-adres-e-mail' post='ogloszenie' value='' urlparam='' class='form-control' output='bootstrap']
	</div>

	[cred_field field='form_submit' value='Wyślij' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']

[/credform]

Please help.

#535200

There are several JS errors in the console of that page.

Does the issue also persist with a WordPress Default Theme and NO Plugins BUT the Toolset Plugins?

If not, could you then re-enable the Plugins one after the other, and check the issue each time you enable a plugin?
Please report me when the issue comes back
It might also be due to the Theme.
Please do reactivate your Theme only after you are sure the issue isn't coming form a 3rd Party Plugin.

Thank you for your feedback

#535231

PZ

Thank you for help. This was very good advice. Now I know that issue is due to autoptimize plugin (https://wordpress.org/plugins/autoptimize/).

When JavaScript code optimization is disabled in autoptimize, everything works fine.

Now I want to enable JavaScript code optimization and set script exception. There is an option in autoptimize to exclude certain scripts from being optimized e. g. I can exclude such scripts: seal.js, js/jquery/jquery.js.

What scripts are used by Toolset that I could exclude form being optimized?

I appreciate your further help.

#535424

Can you try to exclude conditional.js located in the Toolset Common Folders?
In CRED, this is in CRED > Vendor > Toolset > Toolset-Common > Toolset-Forms > JS.

Please let me know if that works.

#536648

PZ

Your solution works. Thank you very much.

Now I have the same kind of problem but with recaptcha. On the same path in /toolset-common/ there are two recaptcha catalogs. Is the script somewhere else?

#536998

I think, the following files should be excluded too:
cred-frontend-editor/library/toolset/cred/embedded/assets/js/cred.js
cred-frontend-editor/library/toolset/cred/embedded/assets/js/settings.js
cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/validation.js
cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/recaptcha-v2/api.js

The rest are PHP scripts that you will not optimize.

Let me know if this solves your issue completely!

#537065

PZ

This time your solution doesn't work. I excluded all the scripts you mentioned plus this one:

/cred-frontend-editor/vendor/toolset/toolset-common/toolset-forms/js/recaptcha-php-1.11/recaptcha_ajax.js

Any other ideas?

#537131

I have to ask, what does not work?

reCaptcha cannot be used as a Condition, are you still having issues with conditionals?
Or is the issue that the reCaptcha is not properly loaded?

I will have to query with the DEV, in that case.

#537139

PZ

Conditionals work fine. Recaptcha is not loading. Recaptcha loads only when I turn off JS optimisation.

#537961

The CRED developer is currently in the weekend and could not fully check what files are needed.

I have to wait for his feedback, which should be due on monday.

I will advise a colleague to update you here.

#539486

recaptcha-v2/api.js is the file you need to exclude.

That is the only one.

Since we do not support optimisation or customization of Plugin Core files, if this does not work, it could be possible that you need custom programming work which is beyond the scope of our support.

At this point I would suggest you consider contacting one of our certified partners from this link:
https://toolset.com/consultant/

You will get the custom assistance you need to get on with your project.

Our of curiosity, do you see any console errors when you use the ReCaptcha?
Or how else does it fail?