I have this code:
<select required="required" class="form-control" name="title">
<option></option>
@foreach ($titles as $key => $val)
@if (stristr($key, 'isGroup'))
<optgroup label="{{ $val }}">
@else
<option value="{{ $key }}">{{ $val }}</option>
@endif
@endforeach
</select>
So when the form have errors i use the line Redirect::route('xpto')->withInput()->withErrors($v)
. But i can't re-populate the select fields. Any way to do this without using JavaScript for example?
The solution is to compare Input::old()
with the $key
variable using Blade Directives - If Statements.
@if (Input::old('title') == $key)
<option value="{{ $key }}" selected>{{ $val }}</option>
@else
<option value="{{ $key }}">{{ $val }}</option>
@endif