Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - Input::old for radio buttons

I was wondering if some Laravel guys can help out.

I have a form in which i have 2 radio buttons, when the form submits it goes through the validator, if the validator fails it comes back to the form, populates the fields with the input and displays error messages.

I cant seem to do this for radio buttons, if one is clicked when the form is submitted and there was an error, it comes back to the form with everything filled out EXCEPT the radio button that was checked is now empty.

My radio buttons are as follows:

<input type="radio" name="genre" value="M" class="radio" id="male" />
<input type="radio" name="genre" value="F" class="radio" id="female" />
<span class="error">{{ $errors->first('genre') }}</span>

Any help would be greatly appreciated.

like image 619
BigJobbies Avatar asked Jun 12 '13 06:06

BigJobbies


1 Answers

You can try this using Laravel's out of the box HTML radio... Laravel Docs Form checkboxes and Radio

Using blade,

{{ Form::radio('genre', 'M', (Input::old('genre') == 'M'), array('id'=>'male', 'class'=>'radio')) }}
{{ Form::radio('genre', 'F', (Input::old('genre') == 'F'), array('id'=>'female', 'class'=>'radio')) }}

Or just php,

echo Form::radio('genre', 'M', (Input::old('genre') == 'M'), array('id'=>'male', 'class'=>'radio'));
echo Form::radio('genre', 'F', (Input::old('genre') == 'F'), array('id'=>'female', 'class'=>'radio'));
like image 106
Melvin Avatar answered Nov 18 '22 06:11

Melvin