0

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

11
  • are you submiting the form through javascript ? otherwise you have to specify button type submit <button class="btn btn-primary" type="submit">SUBMIT</button> Commented Jan 8, 2018 at 8:26
  • no, i did not use javascript Commented Jan 8, 2018 at 8:27
  • add that to the button and try dd to see what are u getting Commented Jan 8, 2018 at 8:27
  • if i may ask, how do i do that? i am not familiar with js Commented Jan 8, 2018 at 8:28
  • just replace your button filed with mine <button class="btn btn-primary" type="submit">SUBMIT</button> Commented Jan 8, 2018 at 8:29

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

if i may ask, how do i do that? im not familiar with js
1

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

11 Comments

this is only snippet of my codes, in my codes (same page) have many different forms
If you want to submit the thing to the same controller then you need to use the common form or the another difficult way would be using JavaScript to do such task . Those two are only the possible way to do so you need to do one of these
im not familiar with js, perhaps you can post it here?
Can you post the full source code of the view page then only I can help with that
i edited my question for your reference, i dont want the select form in each div
|
1

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>

4 Comments

hmmm, not sure why $request->get('getfur'); return null
only 'customer' have its value
okay so the form its being subbmitted correctly. post the dd output how it looks. check $getFuniture if it has value otherwise it will fall back to null @learnprogramming
obviously, the $getFuniture has its id and and its name, i already checked...the codes in the controller $getFuniture = Furniture::where('status, 1)->pluck('fur_name', 'id'); ...the dd output displayed the 'customer' and other bunch of stuffs but not 'getfur'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.