AShishWeb's avatar

How to pass dropdown selected value to another page's dropdown in laravel

I want to pass 3 values (2 dropdown's and 1 input field) from one page to another.User will select 2 dependent dropdowns after clicking on the button user will redirect to another page where he will ask to fill-up a form wherein above 3 details will be auto-filled. The input field's data is passing to another page but the 2 dropdown's value are not passing.

Controller

public function getRequestDetails(Request $request){
        $reqAOP = $request->get('areas');
        $reqType = $request->get('request_type');
        $reqTitle = $request->get('title');
        Session::put('areas', $request->get('areas'));
        return redirect('frontend_template.submitquery')->withInput($request->only('title'));
    }

Blade page

 <div class="col-md-6 float-container">                                                           
      <div class="form-group"  style="margin-bottom: 20px;">                                                                       
      <select style="margin-top: 15px;color: grey;font-size: 16px;" id="aops" class="form-control select2-list">                                                                            
      <option value="{{Session::get('areas')}}" selected>{{Session::get('areas')}}</option>                                                                      
      </select>                                                                    </div>
</div>
 <div class="col-md-6" style="height:33px;color: grey;display: none;width: 49%;line-height: 1;" id="req_options">                                                                    
<div class="form-group"  style="margin-bottom: 20px;">                                                                        
    <select style="margin-top: 15px;color: grey;font-size: 16px;" id="request_type" class="form-control select2-list" >                                                                         
    </select>                                                                      
    </div>
  </div>
 </div>
  <br>
<div class="row form">
 <div class="col-md-12 float-container">
    <div class="form-group"> 
    <input type="text" placeholder="Title *" style="margin-top: 10px;padding-left: 10px;font-size: 16px;" class="form-control" name="title" id="title" value="{{old('title')}}">
 </div>
 </div> 
</div>
0 likes
6 replies
AbdulBazith's avatar

@ashishweb ,

what i understood in your doubt is, you have a form with dropdowns and you will choose the drop down values and those values to be passed to another form when a button is clicked

Am i right?

means you need to do, think that you have form1. you have choosed the dropdowns. think that your dropdown names are dp1 and dp2

then if u click the submit button

it moves to a method in the controller assume that the method is pass_value_to_form2()

so,

public function pass_value_to_form2(Request $request)

{


$dp1=$request->dp1;
$dp2=$request->dp2;

 return view('folder_name.form2')->withDp1($dp1)->withDp2(dp2);

}




If you follow. it is possible

Cronix's avatar

What dropdowns aren't passing? The 2 select elements you are showing don't have a name attribute, so they aren't sent with the form. Only named form controls are, if they are considered "successful" by the html spec (like a checkbox won't be sent unless it's checked, even if it has a name).

1 like
Cronix's avatar

Probably because you are redirecting instead of just returning a view, and passing the variables to the view. Why the need for a redirect? Controller A shows form A. Form A submits to Controller B. Controller B shows Form B using data from Form A that was passed to the view.

AbdulBazith's avatar

@ashishweb sorry for delay.

As per @cronix why you should redirect it. just a return view is enough.

can you show the error?? else whats happening when u try to pass it?

Please or to participate in this conversation.