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

Invalid form name used

Open NicoHood opened this issue 3 years ago • 0 comments

I have a page that adds two forms:

  1. via twig include: {% include "forms/form.html.twig" with { form: forms('testform') } %}
  2. via plugin aka $this->grav['page']->addForms()

Now if I submit the first with invalid data (for example no checkboxes checked, when they are required) and then try to submit the second form with valid data, the error from form 1 is still shown. This does not happen in the other direction or when using multiple forms via twig include.

The issue is, that form.name is using the name of the first form, after submitting. The hidden field for the second form then contains invalid data. It turns out, that normally the second form gets added via onTwigVariables() in form.php, but the if (!isset($twig->twig_vars['form'])) check returns false, as the error message is shown in there.

I have no clue how to fix that, as the logic is super complex.

NicoHood avatar Jan 19 '21 17:01 NicoHood