Skip to content

Bug with form arrays and bodyParser #5

Description

@silkcom

senchalabs/connect#1025 -- I put this error there first, but was directed here.

I just found a wierd bug when using bodyParser and form arrays.

I have a form elements with names of
items[1]
items[2]
etc.

When these submit, I get an array from bodyParser that looks like:
{ items: ['on', 'on'] }

rather than:
{ items: { 1: 'on', 2: 'on' } }

If instead I change the form to have names of
items[id_1]
items[id_2]

it works great (except now I need to replace id_)

dougwilson over on the other form brings up a good point against treating it like an array, but honestly just dropping the values on the floor is worse than the possible problem. Making it always an object if the id's are specified seems like the only answer. That way it works the same as PHP does, which makes a lot of sense.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions