Search code examples
htmllaraveldropdown

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>

Solution

  • You can create a button like this to pass the value to next request/page

    <a href="{{route('route_name',['area'=>'$variable','request_type'=>'$variable','title'=>''])}}"
                                       class="btn btn-primary" style="text-decoration:none">
       <i class="fa fa-folder-open"></i>Manage
    </a>
    

    In route you just need to declare the path like

    Route::get('blade_path/{area}/{request_type}/{title}','Controller@function')->name('route_name');