Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jarminkhan's avatar

How to use old() function with radio button!!!!

I have arrays of radio named "radio[]" with 5 options to choose from. I need to retain the inputed data when validation fails. How do we use old() function with radio buttons?

5 4 ...

0 likes
2 replies
Nakov's avatar

Aren't you using it wrong? Radio buttons are used more to select one option out of many, and checkbox is used more for multiple selection, so you should not have a name as an array on the radio button. Then a simple check if the old value is the same as the one selected you should print out checked.

<input type="radio" name="radio" value="1" {{ old("radio") == '1' ? 'checked' : '' }}>

if you use checkbox instead or the name as an array just check if the value is contained in the array.

<input type="radio" name="radio[]" value="1" {{ in_array('1', old("radio")) ? 'checked' : '' }}>

Let me know if it works.

Please or to participate in this conversation.