简体   繁体   中英

Laravel, how to get all value from different form in a same page?

As you can see the code below, I have 2 forms in a same page. How to I to pass all the value('getfur' and 'customer') to controller after I press the submit button in the second form? This is only a snippet of my codes.

I already tried this in controller like this below, but it return null

$getAllInput = $request->all();
dump($getAllInput );  //return null

view

{!! Form::open() !!}
<div class="form-group">
    <label>Furniture</label>
        {!!  Form::select('getfur',$getFuniture, null, ['class'=>'form-control', 'placeholder' => '--- Select Furniture---']) !!}
</div>
{!! Form::close() !!}




{!! Form::open(['route'=>['fur.store','id'=>'myAppForm']) !!}
<div class="form-group">
    <label>Customer</label>
        {!!  Form::text('customer', null, ['class'=>'form-control']) !!}
    <button class="btn btn-primary">SUBMIT</button>
</div>
{!! Form::close() !!}

EDIT (FULL CODE)

{!! Form::open() !!}
<div class="form-group">
    <label>Furniture</label>
        {!!  Form::select('getfur',$getFuniture, null, ['class'=>'form-control', 'placeholder' => '--- Select Furniture---']) !!}
</div>
{!! Form::close() !!}




{!! Form::open(['url'=>['fur/1','id'=>'myAppForm']) !!}
<div class="form-group">
    <label>Customer</label>
        //some input form
    <button class="btn btn-primary">SUBMIT</button>
</div>
{!! Form::close() !!}

{!! Form::open(['url'=>['fur/2','id'=>'myAppForm']) !!}
<div class="form-group">
    <label>Customer</label>
        //some input form
    <button class="btn btn-primary">SUBMIT</button>
</div>
{!! Form::close() !!}

{!! Form::open(['url'=>['fur/3','id'=>'myAppForm']) !!}
<div class="form-group">
    <label>Customer</label>
        //some input form
    <button class="btn btn-primary">SUBMIT</button>
</div>
{!! Form::close() !!}

and so on...until the url reaches 'fur/20', i dont want the select form in each div

You need to use javascript to do it. Bind a listener "onClick" to the submit button and then get all values you need and send it to the server using jQuery.post() for example.

You can combine the two input of the two forms . You don't need to open and close the two forms . Only opening and closing of one form will do the job .

{!! Form::open(['route'=>['fur.store','id'=>'myAppForm']) !!}
<div class="form-group">
    <label>Furniture</label>
    {!!  Form::select('getfur',$getFuniture, null, ['class'=>'form-control', 'placeholder' => '--- Select Furniture---']) !!}
</div>
<div class="form-group">
<label>Customer</label>
{!!  Form::text('customer', null, ['class'=>'form-control']) !!}
<button class="btn btn-primary">SUBMIT</button>
</div>
{!! Form::close() !!}

and in controller you can do like this

$getAllInput = $request->all();
dump($getAllInput );  //return null

So what you could do its grab the id's and submit them using javascript:

{!! Form::open() !!}
<div class="form-group">
    <label>Furniture</label>
        {!!  Form::select('getfur',$getFuniture, null, ['class'=>'form-control', 'placeholder' => '--- Select Furniture---','id'=>'myAppForm']) !!}
</div>
{!! Form::close() !!}




{!! Form::open(['route'=>['fur.store','id'=>'myAppForm1']) !!}
<div class="form-group">
    <label>Customer</label>
        {!!  Form::text('customer', null, ['class'=>'form-control']) !!}
    <input type="button" value="Submit" onclick="submitForms()" />
</div>
{!! Form::close() !!}

Then add javascript after html:

<script type = "text/javascript">
    submitForms = function(){
        document.getElementById("myAppForm").submit();
        document.getElementById("myAppForm1").submit();
    }
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM