masonite icon indicating copy to clipboard operation
masonite copied to clipboard

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

Open ssestantech opened this issue 2 years ago • 3 comments

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.

ssestantech avatar Nov 09 '22 09:11 ssestantech

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

girardinsamuel avatar Nov 09 '22 09:11 girardinsamuel

<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>

ssestantech avatar Nov 09 '22 09:11 ssestantech

@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

circulon avatar Jan 05 '23 00:01 circulon