Laravel 5.1 how to use the {{old ('')}} helper in the clip file for radio inputs

I am currently studying laravel and creating my first form. All this is awesome as long as I don't want to use the {{old ('')}} helper in my click file for radio buttons. I am not sure how to do it right, and I cannot find much information here about this.

The code I have is as follows:

<div class="form-group">
    <label for="geckoHatchling">Gecko Hatchling?</label>
    <div class="radio">
        <label>
            <input type="radio" name="geckoHatchling" id="geckoHatchlingYes" value="1">
            Yes
        </label>
    </div>
    <div class="radio">
        <label>
            <input type="radio" name="geckoHatchling" id="geckoHatchlingNo" value="0" checked>
            No
        </label>
    </div>
</div>
+4
source share
2 answers

I think the following is a little cleaner:

<input type="radio" name="geckoHatchling" id="geckoHatchlingYes" value="1" @if(old('geckoHatchling')) checked @endif>

<input type="radio" name="geckoHatchling" id="geckoHatchlingYes" value="1" @if(!old('geckoHatchling')) checked @endif>

@ifchecks the plausibility of the old value and displays checkedin any case.

+8
source

Form-helper, Laravel. . .

WITH FORM-HELPER

1.

{!! Form::radio('geckoHatchling', '1', (Input::old('geckoHatchling') == '1'), array('id'=>'geckoHatchlingYes', 'class'=>'radio')) !!}
{!! Form::radio('geckoHatchling', '0', (Input::old('geckoHatchling') == '0'), array('id'=>'geckoHatchlingNo', 'class'=>'radio')) !!}

2. PHP

echo Form::radio('geckoHatchling', '1', (Input::old('geckoHatchling') == '1'), array('id'=>'geckoHatchlingYes', 'class'=>'radio'));
echo Form::radio('geckoHatchling', '0', (Input::old('geckoHatchling') == '0'), array('id'=>'geckoHatchlingNo', 'class'=>'radio'));

-

1.

<input type="radio" name="geckoHatchling" id="geckoHatchlingYes" value="1" @if(Input::old('geckoHatchling')) checked @endif>
<input type="radio" name="geckoHatchling" id="geckoHatchlingNo" value="0" @if(!Input::old('geckoHatchling')) checked @endif>

2. PHP

<input type="radio" name="geckoHatchling" value="1" class="radio" id="geckoHatchlingYes" <?php if(Input::old('geckoHatchling')== "1") { echo 'checked'; } ?> >
<input type="radio" name="geckoHatchling" value="0" class="radio" id="geckoHatchlingNo" <?php if(Input::old('geckoHatchling')== "0") { echo 'checked'; } ?> >
+8

Source: https://habr.com/ru/post/1611714/


All Articles