getgrav / getgrav/grav-plugin-form
Invalid form name used
- Dominant language
- PHP
- Stars
- 64
- Forks
- 80
- Avg merge
- 10h 13m
- Merged PRs (30d)
- 9
Description
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in form.php, especially onTwigVariables() and the check for twig_vars['form']; reproduce the two-form case described in the issue by submitting invalid data in the Twig-included form before submitting the plugin-added form. Done means the second form keeps its own name and does not display the first form's validation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100