grav-plugin-form icon indicating copy to clipboard operation
grav-plugin-form copied to clipboard

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

Open AnneSalem opened this issue 3 years ago • 6 comments

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:

  • Grav v1.6.28
  • Form v4.1.2
  • PHP 7.4

Any ideas on how to solve this issue?

AnneSalem avatar Dec 01 '20 15:12 AnneSalem

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

rhukster avatar Dec 01 '20 16:12 rhukster

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?

AnneSalem avatar Dec 01 '20 17:12 AnneSalem

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

mahagr avatar Dec 02 '20 10:12 mahagr

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

AnneSalem avatar Dec 02 '20 13:12 AnneSalem

@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 avatar Dec 02 '20 15:12 mahagr

I'm reopening this issue, CC @rhukster

Should we fix those skeletons?

mahagr avatar Dec 10 '20 06:12 mahagr