MasoniteFramework / masonite

The Modern And Developer Centric Python Web Framework. Be sure to read the documentation and join the Discord channel for questions: https://discord.gg/TwKeFahmPZ
http://docs.masoniteproject.com
MIT License
2.22k stars 126 forks source link

how to get value from form with multiple inputs with same name and save in db. #734

Closed ssestantech closed 3 months ago

ssestantech commented 2 years ago

Describe the bug

how to get value from form with multiple inputs with same name and save in db.

Expected behaviour

how to get value from form with multiple inputs with same name and save in db.

Steps to reproduce the bug

No response

Screenshots

No response

OS

Windows

OS version

window 11

Browser

No response

Masonite Version

4.6.1

Anything else ?

how to get value from form with multiple inputs with same name and save in db.

girardinsamuel commented 2 years ago

Hi ! Could you post an example of your HTML form in this issue ?

ssestantech commented 2 years ago
<form class="multisteps-form__form" action="{{url('postform')}}" method="post" enctype="multipart/form-data">
          {{ csrf_field }}
<input type="text" name="childrenname[]">
<input type="text" name="childrenname[]">
</form>
circulon commented 1 year ago

@ssestantech

Your issue has nothing to do with Masonite. Its due to the name of your fields in the form not being unique.

This same issue will happen with many languages & frameworks when parsing the HTML input fields name parameter.

See here for a complete explanation of your issue and how to solve getting the inputs in grouped by the parent childrenname as a list

https://mattstauffer.com/blog/a-little-trick-for-grouping-fields-in-an-html-form/

Hope this helps