Closed nclm closed 2 years ago
Perhaps @mahagr can better answer this, but from my knowledge, the data[xxx]
syntax is just how Grav forms work. There are other internal form hidden inputs that are at the root of the form (nonce, remember-me, etc) and putting the form data inside a specific data[]
array ensures we can easily get to that data without having to manually strip out any other extraneous input fields. So it's really just an internal thing so that Grav forms can function reliably.
However, there's nothing stopping you from just creating a form manually in Twig, rather than using Grav forms for your definition. I've done that several times where I just need a simple form that is being sent or processed by an external service (mailinglist signup for example). You create it in the same HTML structure with the same CSS as a Grav form, so the styling matches.
Like @rhukster said, the reason why we embed fields to data is to prevent task, form id, unique key, etc from leaking into the data. There's a way to change where the data will be stored, but I don't recommend changing it.
In twig, there's scope
variable that defines the prefix, but changing it will break the forms.
Okay thanks, I understand.
I do believe it would be good to be able to access the proper name field in cases someone wants to build a custom form. It's quite a nice form system you have, and it's a pity to go back to the template just to add a form on one page (and create a new template just for that one page that have a form). It’s also makes it impossible to edit the form for less technical users or users who don't have access to the FTP. It's also not possible to use the feature of importing a form from another page.
Could there be an extra attribute, html-name
or something, to override the Grav generated name attribute? Unadvised, only for special cases, but available for those who need it?
You can try setting scope
in twig if you handle the data yourself. I think it defaults to data.
(with dot in the end).
Hi,
I’m making a form that has a field like this:
However, it is converted into this HTML:
Instead of:
How do I make it
name="XXX"
and notname="data[XXX]"
?I’m sending the form through
POST
to an external service, so it is important for the field name not to be anything else.Thanks!