Skip to content

Bind formdata with array input.  #1644

@mytc

Description

@mytc

I having having problem with binding the form data.
The input would be like this

<input name="codes[1][icode]" type="number" />
<input name="codes[1][limit]" type="text" />
<input name="codes[2][icode]" type="number" />
<input name="codes[2][limit]" type="text" />

And the struct

type Event struct {
	gorm.Model
	Code []InvideCode `form:"codes"`
}


type InvideCode struct {
	gorm.Model
	EventID uint 
	Code string `form:"icode"`
	Limit string `form:"limit"`
}

And i bind it with
event := new(Event)
or
c.FormValue("codes")

Both give me the empty value.
What did I done wrong?

Actually there is similar problem was asked at SO , the accepted answer is using 3rd party library and I don't like it. I wonder if there any Echo way to do it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions