Radio Button back with old value

Asked

Viewed 34 times

1

Hello!

I have the following code:

     <div class="resposta">
        <label class="radio-inline" style="padding-right: 20px;">
            <input type="radio" name="1" value="S" {{ old('resposta1') == "S" ? 'checked' : '' }}>SIM
        </label>
        <label class="radio-inline">
            <input type="radio" name="1" value="N" {{ old('resposta1') == "N" ? 'checked' : '' }}>N&atilde;o
        </label>
    </div>

In my controller I am doing the Validator :

    $resposta1 = $request->input( '1' );
    $resposta2 = $request->input( '2' );
    $resposta3 = $request->input( '3' );

    $validator = Validator::make(
        [
          'resposta1' => $resposta1,
          'resposta2' => $resposta2,
          'resposta3' => $resposta3,
        ],
        [
           'resposta1' => 'required',
           'resposta2' => 'required',
           'resposta3' => 'required'
        ]
    );

    if( $validator->fails() ){
         return redirect()->back()->withErrors( $validator )->withInput();
    }

I wish that in case of this error, that when returning the radios were checked if it had been checked beforehand.

But this code of mine is not working

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.