Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request does not return all data from the form

Tags:

html

php

I have a section in which a user can add input values and can add an input field as many as he/she wants. the first input field is default added to the DOM.

The form looks like this

enter image description here

Here is HTML for this form assume user added one input field

<dvi class="container h-100">
    <div class="d-flex justify-content-center">
        <div class="card mt-5 col-md-12 animated bounceInDown myForm" id="multiple-container">
            <div class="card-header">
                <h4>Bidders Information</h4>
            </div>
            <div class="card-body" id="add_info">

                <div id="dynamic_container">
                    <small id="bidder">Bidder 1</small>
                    <span class="bmd-form-group"><div class="input-group">
                            <div class="input-group-prepend">
                              <span class="input-group-text br-15"><i class="fa fa-tags"></i></span>
                </div>
                <input type="text" placeholder="Bidders Name" name="bidder_name" class="form-control">
            </div>
            </span>
            <span class="bmd-form-group"><div class="input-group mt-3">
                            <div class="input-group-prepend">
                              <span class="input-group-text br-15"><i class="fa fa-tags"></i></span>
        </div>
        <input type="text" placeholder="atribute name" name="params_name" id="field1" class="form-control">
        <input type="text" placeholder="atribute value" name="params_value" id="field2" class="form-control">
        <a class="btn btn-secondary btn-sm moreinput_field" id="add_more_input">
            <i class="fa fa-plus-circle"></i>
        </a>
    </div>
    </span>
    </div>

    </div>
    <div class="card-body" id="add_info0">

        <div id="dynamic_container">
            <small id="bidder">Bidder 2</small>
            <span class="bmd-form-group"><div class="input-group">
                            <div class="input-group-prepend">
                              <span class="input-group-text br-15"><i class="fa fa-tags"></i></span>
        </div>
        <input type="text" placeholder="Bidders Name" name="bidder_name" class="form-control">
    </div>
    </span>
    <span class="bmd-form-group"><div class="input-group mt-3">
                            <div class="input-group-prepend">
                              <span class="input-group-text br-15"><i class="fa fa-tags"></i></span>
    </div>
    <input type="text" placeholder="atribute name" name="params_name" id="field1" class="form-control">
    <input type="text" placeholder="atribute value" name="params_value" id="field2" class="form-control">
    <a class="btn btn-secondary btn-sm more_input moreinput_field" id="add_more_input0">
        <i class="fa fa-plus-circle"></i>
    </a>
    </div>
    </span>
    <a class="btn btn-danger btn-sm" id="remove-more"><i class="fa fa-trash"></i></a>
    </div>
    </div>
    <div class="card-footer" id="card-footer">
        <a class="btn btn-success btn-sm" id="add_more"><i class="fa fa-plus-circle"></i> Add<div class="ripple-container"></div></a>

        <button class="btn btn-success btn-sm float-right submit_btn"><i class="fas fa-arrow-alt-circle-right"></i> Submit</button>
    </div>
    </div>
    </div>
</dvi>

On my controller, I have this.

   public function store(Request $request){

            dd($request);
    }

Which return me the following

enter image description here

as you can see it return only the second input fields

What is wrong with my code???

like image 505
The Dead Man Avatar asked Jun 12 '26 16:06

The Dead Man


2 Answers

You have to tell laravel that it's a collection of names for example this :

<input type="text" placeholder="Bidders Name" name="bidder_name" class="form-control">

Should be like this :

<input type="text" placeholder="Bidders Name" name="bidder_name[]" class="form-control">
like image 97
Maraboc Avatar answered Jun 15 '26 04:06

Maraboc


The reason you are getting only 1 value is because your HTML attributes have the same name

<input type="text" placeholder="Bidders Name" name="bidder_name" class="form-control">

In the above the name attribute is bidder_name which will be same for both the rows. So you are only getting the 2nd Row.

You can change it like below

<input type="text" placeholder="Bidders Name" name="bidder_name[]" class="form-control">

Same changes needs to be made for other 2 HTML Form Elements.

like image 41
ascsoftw Avatar answered Jun 15 '26 04:06

ascsoftw