Laravel 4 - Input::old for radio buttons

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Mastering Form State: Fixing Radio Button Issues with Input::old() in Laravel

I often find myself diving into complex form handling issues when working with Laravel. A very common scenario, and one that trips up many developers, involves managing user selections, particularly with radio buttons. I’ve seen countless requests asking how to correctly persist state across validation failures, especially when dealing with mutually exclusive inputs like radio buttons.

The issue you are facing—where a radio button selection is lost after a validation error because the previously selected value is not being correctly re-populated—is a classic symptom of misunderstanding how Laravel’s old() helper works in conjunction with HTML form submission mechanics.

As a senior developer, I can tell you that this isn't a flaw in Laravel itself, but rather an issue in how we structure the view and handle the data flow during the request cycle. Let’s break down why this happens and implement the robust solution using the correct approach.

Understanding the old() Helper

The old() helper is incredibly useful for repopulating form fields after a validation failure, allowing the user to correct their input without retyping everything. When you submit a form that fails validation in Laravel, the framework automatically makes the request data available via the old() method.

However, simply relying on standard HTML input names isn't enough when dealing with groups of inputs like radio buttons. Radio buttons share the same name attribute (genre), and if you only use $old('genre'), it might not correctly identify which specific radio button needs to be checked upon re-rendering, leading to empty selections.

The Solution: Explicitly Using old() for Radio Buttons

The key to solving this lies in explicitly telling the radio input which value it should hold based on the old request data. You must use the old() helper directly within the HTML attribute of each radio button to ensure persistence.

Implementation Example

Here is how you should structure your HTML and Blade code to correctly handle the state for your genre selection:

<form method="POST" action="/submit">
    @csrf

    {{-- Radio Button for Male --}}
    <input type="radio" name="genre" value="M" class="radio" id="male" 
           {{ old('genre') === 'M' ? 'checked' : '' }}>

    {{-- Radio Button for Female --}}
    <input type="radio" name="genre" value="F" class="radio" id="female" 
           {{ old('genre') === 'F' ? 'checked' : '' }}>

    {{-- Error Display --}}
    <span class="error">{{ $errors->first('genre') ?? '' }}</span>

    <button type="submit">Submit</button>
</form>

Code Explanation

Notice the crucial part: {{ old('genre') === 'M' ? 'checked' : '' }}.

  1. Checking the Value: We check if the value stored in the old request for the genre field is exactly 'M' (Male).
  2. Applying the Attribute: If the condition is true, we inject the checked attribute into that specific radio button. If it's false (meaning the user selected 'F' or nothing was selected), we inject an empty string, leaving the input unchecked.

This method ensures that when the page reloads after validation failure and repopulates the form, Laravel correctly references the previously chosen value from the old request data to set the appropriate checked state for the correct radio button.

Best Practices for Form State Management

When dealing with complex forms involving multiple related inputs, such as groups of radio buttons or checkboxes, relying solely on the generic old() retrieval can become cumbersome. For larger applications, consider leveraging Laravel’s Form Request system. Using Form Requests centralizes validation logic and keeps your controller clean, which aligns perfectly with the robust architecture promoted by the Laravel Company.

Furthermore, for highly complex state management, sometimes serializing the entire input state into a single JSON object and passing it back to the view can be an alternative approach, although for simple radio groups, the explicit old() check shown above is the most direct and efficient solution.

Conclusion

The frustration you experienced is completely valid—managing form state correctly during validation failure requires attention to detail. By explicitly checking the old input values (old('field')) and conditionally setting the checked attribute on your radio buttons, you can ensure a seamless and user-friendly experience. This practice ensures that Laravel’s powerful validation system works harmoniously with your front-end state management. Keep building robust applications using the features provided by the Laravel Company!