Categories
CMS Mastering Development

Freeform form throws error on submitting hidden field with JSON

I’ve been running into a strange error with the Freeform plugin. I have made a form that has a hidden input field which gets occupied with JSON. This JSON data then is decoded in the e-mail notification for correct displaying.

A little more info for clarification:

The user can select multiple products from different product groups on the page. The selected products are put into a JSON object with javascript and the hidden input field is filled/updated on choosing a product.

When selecting 2 or 3 products, the form is submitted successfully and the e-mail notification is sent with the correct data. When selecting more than 3 products (from 1 product group or more, doesn’t matter) the form does not submit and the error message is displayed.

I have logged the form.errors object in my code as followed:

Which returns the following if the error occurs:

/home/vagrant/sites/citymesh/citymesh_insky-website/vendor/twig/twig/src/Extension/DebugExtension.php:61: array (size=0) empty

Example of the json that is put into the hidden input field:

  "group-1": {
    "name": "Group 1",
    "products": [
      {
        "name": "Start",
        "id": "11087",
        "price": "10",
        "amount": 50
      },
      {
        "name": "Plus",
        "id": "11090",
        "price": "20",
        "amount": 10
      }
    ]
  },
  "group-2": {
    "name": "Group 2",
    "products": [
      {
        "name": "Start",
        "id": "11122",
        "price": "8",
        "amount": 5
      },
      {
        "name": "Plus",
        "id": "11125",
        "price": "12",
        "amount": 10
      }
    ]
  }
}

The Freeform log and phperrors log are empty after this error occurs, so I’m out of ideas what the issue could be. Does anyone have a lead to where the problem might be?

Leave a Reply

Your email address will not be published. Required fields are marked *