I have a form with dropdown boxes, a radio buttons, and a few text fields. I know how to keep the text field values after form submit, but I would like to keep the dropdown value/data after submit. I am posting to the same page. here is the code below
<div class="form-group row">
<label class="col-sm-3 col-form-label">{{trans('words.shows_text')}}*</label>
<div class="col-sm-8">
<select class="form-control select2" name="series" id="episode_series_id">
<option value="">{{trans('words.select_show')}}</option>
@foreach($series_list as $series_data)
<option value="{{$series_data->id}}" @if(isset($episode_info->id) && $series_data->id==$episode_info->episode_series_id) selected @endif>{{$series_data->series_name}}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">{{trans('words.seasons_text')}}*</label>
<div class="col-sm-8">
<select class="form-control select2" name="season" id="episode_season_id">
<option value="">Select Season</option>
@if(isset($episode_info->id))
@foreach($season_list as $i => $season_data)
<option value="{{ $season_data->id }}" @if($season_data->id==$episode_info->episode_season_id) selected @endif>{{ $season_data->season_name }}</option>
@endforeach
@endif
</select>
</div>
</div>
You can use the session variables. So, first start the session:
When the form is submitted, store the selected values in session variables:
And finally, use the session variables to set the checked attribute of the appropriate input elements:
Of course, you will need to make some extra "ifs" in your code.