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

liamvictor's avatar

Gotcha - Using 'name' as a form name field stopped old() from working as expected.

edit - I'm an idiot. Something else was messing with the "name" values.

I ran in circles with this for a long time so thought I'd document it here in case it saves anyone else an hour of hair-pulling.

Controller has the line

    public function store(Request $request)
    {
        request()->session()->flash('info', "Name:" . request()->name . " Foo:" . request()->foo);
        return back()->withInput();
    }

Form is

<form class="form" action="/blocks" method="POST">

    @csrf

    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            <button type="submit" class="btn btn-primary">
                Add Email Blocks
            </button>
        </div>
    </div>

    <div class="form-group">
        <label for="foo">foo</label>
        <input type="text" name="foo" id="foo" class="form-control" value="{{ old('foo') }}">
    </div>

    <div class="form-group">
        <label for="name">Name</label>
        <input type="text" name="name" id="name" class="form-control" value="{{ old('name') }}">
    </div>
</form>

Submitting the form the "name" field was never updated, but foo would be.

Thought i'd submit this here as Laracasts ranks highly for Laravel issues so this might help someone in the future.

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

@liamvictor that does not make sense. Just tested your code in my project and it works as expected.. Make sure you don't have a problem with the session for some reason.

  • Test in a different browser.
  • Do you use file as a SESSION_DRIVER?
  • Or having a JavaScript that clears the value for this field as well.
1 like
liamvictor's avatar

You're right, something else is fiddling with the name field. I did it in another project and it worked as expected.

Sorry for any confusion I cause others! Unfortunately there doesn't seem to be a delete to get rid of my erroneous message.

Please or to participate in this conversation.