Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

populate old html select field in laravel upon failure

i have a form with a select input, validation is fine, but upon failure the select field doesn't populate the old value here is my select field

  <div class="control-group">
   <label class="control-label">Gender :</label>
    <div class="controls">
        <select  name="gender" value= "{{ Input::old('gender') }}">
            <option>Select</option>

                <option value="M">Male</option>
                <option value="F">Female</option>
        </select>
    </div>
</div> 

how can i solve this?

like image 461
dxcoder1 Avatar asked Oct 03 '14 05:10

dxcoder1


1 Answers

If you don't want to use Laravel Form build, you need to do it this way:

 <div class="control-group">
   <label class="control-label">Gender :</label>
    <div class="controls">
        <select  name="gender">
            <option>Select</option>

                <option value="M" @if (Input::old('gender') == 'M') selected="selected" @endif>Male</option>
                <option value="F" @if (Input::old('gender') == 'F') selected="selected" @endif>Female</option>
        </select>
    </div>
</div> 
like image 130
Marcin Nabiałek Avatar answered Sep 17 '22 22:09

Marcin Nabiałek