Open frapell opened 1 year ago
We also have this issue on production sites. I agree with the renaming being a good fix option, maybe be aware that it might break honeypot solutions since they use field id's. Does anyone know if this issue also happens in collective.easyform, or how it's fixed there?
As far as I know, there is no option to copy fieldsets in collective.easyform. If users manually try to reuse a name/id in 2 fieldsets, easyform prevents it due to a validation check. People could in theory bypass the validation by editing the xml directly, which leads to other validation issues on sent.
@spereverde Could you expand a bit on what you mean by "honeypot solutions" ?
@frapell sure.
In easyform there is a custom class field for this, in pfg I guess this honeypot field would be hidden with custom css or css inside a package somewhere, using the field's unique css id/class (= shortname of field). I guess in most cases it's not a problem since the honeypotfield is usually not inside a folder or a fieldset, but when it is developers would have to update the css in their setups
Maybe useful to note that we usually have this issue with old and new style fieldsets, and not with folders
@spereverde Thanks! wasn't aware of such techniques :) My idea of fix (by prefixing the fieldset id to the field id) should only affect the fields created inside fieldsets, so these should continue to work fine... I guess a note should be made in the README to be very clear how it works.
I fear that this may break custom code, for example custom validators or scripts that expect to find "name" in the request, and now it should be "fieldset-name" or something. But then: if submitting already does not work, and this fixes it, then it is a win.
But I would only change these names/ids on the fly when it is really needed. So only change anything when there actually is a duplicate field name.
For consistency, we might consider using validation as in easyform?
Having 2 fields with the same
id
(i.e. when an existingfieldset
is copied) leads to unintended errors.Steps to reproduce:
FormFolder
FieldsetFolder
calledFolder 1
FormStringField
inside of it calledName
(It should default to255
forMax Length
, if not, make it so)FormFolder
go tofolder_contents
viewFolder 1
, clickcopy
and thenpaste
Folder 2
withfolder-2
as idAt this point, you should have a
/folder-1
and/folder-2
folders, and aname
field inside each of them.If you submit this form, you get
The reason for this, is because the form has 2 fields with the same
id
, and so when the form gets submitted, instead of having 2 separate values, they are merged and treated as a list with 2 values.Now, if you manually create the second folder, instead of copy & pasting, the field inside of it will be named
name-1
, which prevents this bug.A possible fix would be to add a subscriber so when pasting content, it will be traversed and all children would be renamed to avoid conflicts...
A better fix in my opinion would be to add a prefix to the field
id
andname
attributes qhen rendering the form, containing the fieldsets ids. So for instance in this case, the form would have 2 fields, one with anid
andname
offolder-1-name
and a second one withid
andname
offolder-2-name