Skip to content

Incompatibility with kirby-minify-html + possible fix #15

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

Closed
rantonse opened this issue Mar 12, 2023 · 4 comments
Closed

Incompatibility with kirby-minify-html + possible fix #15

rantonse opened this issue Mar 12, 2023 · 4 comments

Comments

@rantonse
Copy link

Hi, and thanks for the plugin!

There is an incompatabilty with afbora/kirby-minify-html.

To reproduce, I added the latest versions of both plugins to the starter kit

After adding a form to the home page, and clicking send without any fields filled out, you get both a 404 error and a parse error.

The reason for the error is that the kirby-minify-html plugin removes comments. After some experimentation, I found out that the kirby-minify-html plugin does not remove conditional comments (with the <!--[if IE]> syntax), so a fix would perhaps be to change the comments syntax?

I tried that with success, and only two files need to be slightly changed:

The changes I did are here:

Basically, these are the changes to the validation.php file:

  • Changing <!-- Startvalidation:<?= $form->id() ?> --> to <!--[Startvalidation:<?= $form->id() ?>]-->.
  • Changing <?php ?> to <!--[<?php ?>]-->.
  • Changing <!-- Endvalidation --> to <!--[Endvalidation]-->.

Then, in index.php, changing the regexp

  • from /\<\!-- Startvalidation:'.get('id').' --\>(.*?)\<\!-- Endvalidation --\>/s
  • to /\<\!--\[Startvalidation:' . get('id') . '\]--\>\s\<\!--\[(.*?)\]--\>\s\<\!--\[Endvalidation\]--\>/s.

Do you see any downsides to this change?

@plain-solutions-gmbh
Copy link
Owner

Thanks for your suggestion. Your example breaks the Validation because the JSON outputs HTML and the comment falls out. I hope i explained clearly. If i uncomment the oncoming JSON, the validation will work. But i don't know, if the minify will remove that json. I fixed it in 3.4.7. Can you test it?
If not: Probably the minify-plugin has an option to exclude i specific url.

Just let me know

@rantonse
Copy link
Author

I am not sure I completely understand. I tried the 3.4.7 fix on a fresh installation, but the error remains.

On my end, I got it to work by wrapping the middle <?php ?> part in validation.php within <!--[ and ]-->.
In other words, <?php ... ?> becomes <!--[<?php ... ?>]-->.
For the regular expression in index.php, I replaced (.*?) with \s\<\!--\[(.*?)\]--\>\s.

I am not sure if this is a good idea, but this is my current workaround. :)

@plain-solutions-gmbh
Copy link
Owner

That will break the inline validation. (Autovalidation during form fill). You can check it in your console:

  1. Open Devtool console
  2. Enter a text in a field
  3. Go to another field

Your code will probably case an error. Because inside '' will be a JSON with HTML-Code. Which break the comments. Can you confirm that?

@plain-solutions-gmbh
Copy link
Owner

Since I haven't heard anything more, it seems to me that a solution to this problem has been found. I'il close this issue.

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

2 participants