getgrav / grav-plugin-form

Grav Form Plugin
http://getgrav.org
MIT License
53 stars 79 forks source link

RuntimeError when using checkbox, spacer or honeypot fields under PHP 7.4 #457

Open AnneSalem opened 3 years ago

AnneSalem commented 3 years ago

I get the following RuntimeError when using checkbox, spacer or honeypot fields under PHP 7.4. Under PHP 7.3 everything works as expected without errors.

An exception has been thrown during the rendering of a template 
("Trying to access array offset on value of type int").

.../user/plugins/form/templates/forms/default/field.html.twig9

The definition of the affected fields is done on a modular page and looks as follows:

- agree_to_terms:
  type: checkbox
  validate:
    required: true
  outerclasses: privacy-checkbox

- agree_to_terms_text:
  type: spacer
  text: Ich habe die Datenschutzerklärung gelesen und bin einverstanden *

- honeypot:
  type: honeypot

Issue exist on:

Any ideas on how to solve this issue?

rhukster commented 3 years ago

Are you on the latest released version of Form plugin? I can run fine under PHP 7.4, even PHP 7.8 with checkbox and radio fields. I'll have to get a test page with your blueprint elements though (although they look fine).

AnneSalem commented 3 years ago

Thank you for the quick reply. Yes, the version is v4.1.2. I also tried to delete the plugin and reinstall it. In my case just one of the fields is enough to produce the error. Text inputs and textareas are working fine. Should I copy the whole form definition here?

mahagr commented 3 years ago

Try writing the form in this format:

agree_to_terms:
  type: checkbox
  validate:
    required: true
  outerclasses: privacy-checkbox

agree_to_terms_text:
  type: spacer
  text: Ich habe die Datenschutzerklärung gelesen und bin einverstanden *

honeypot:
  type: honeypot

So basically remove dash from the form fields, it's not supported.

PS: Dash format works without the key like this:

-
  name: agree_to_terms
  type: checkbox
  validate:
    required: true
  outerclasses: privacy-checkbox
-
  name: agree_to_terms_text
  type: spacer
  text: Ich habe die Datenschutzerklärung gelesen und bin einverstanden *
-
  name: honeypot
  type: honeypot
AnneSalem commented 3 years ago

Thanks a lot, now it works! 🎉😊

I got the template for the (not supported) formatting from the link "Page markdown file" on the Grav documentation page: https://learn.getgrav.org/16/forms/forms/example-form

mahagr commented 3 years ago

@rhukster It looks like some of the skeletons have bad blueprint markup:

https://raw.githubusercontent.com/getgrav/grav-skeleton-soraarticle-blog/develop/pages/03.contact/form.md

That format has never been supported, so likely the form has never been properly validated.

mahagr commented 3 years ago

I'm reopening this issue, CC @rhukster

Should we fix those skeletons?