Reputation: 971
I am looking a way to create a form for an appointment, I have 2 fields so far, in format "string", is it correct according you?
<fieldset class="form-group {{ $errors->has('hour_start') ? 'has-error' : '' }}">
<label for="company-content">Hour Start</label>
<select name="hour_start" id="" class="form-control">
<option value="">Hour Start</option>
<option value="08:00" @if (old('hour_start') == "08:00") {{ 'selected' }} @endif>08:00</option>
<option value="10:00" @if (old('hour_start') == "10:00") {{ 'selected' }} @endif>10:00</option>
</select>
</fieldset>
<fieldset class="form-group {{ $errors->has('hour_end') ? 'has-error' : '' }}">
<label for="company-content">Hour End</label>
<select name="hour_end" id="hour_end" class="form-control">
<option value="">Hour End</option>
<option value="10:00" @if (old('hour_end') == "10:00") {{ 'selected' }} @endif>10:00</option>
<option value="13:00" @if (old('hour_end') == "13:00") {{ 'selected' }} @endif>13:00</option>
</select>
</fieldset>
I think the validation will be complicated?
Thank you for your help.
Upvotes: 0
Views: 42
Reputation: 11
You can also just put your options in an array and use foreach,if you need to add other options later on it will simplify it, up to you.
$options = ['10:00','13:00'];
@foreach($options as $opt)
<option value="{{$opt}}" @if (old('hour_end') == $opt) {{ 'selected' }} @endif>{{$opt}}</option>
@endforeach
Upvotes: 1