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

GiacomoM's avatar

Input old and array

Hi, I have a form like this:

<input type="text" name="field[]" />

I need to retrieve the value with the old function, but I am not able to. How can I do that?

Thanks.

0 likes
13 replies
Snapey's avatar

You can't have an array with a single field. Can you explain more what you are trying to do? Why is it an array?

Do you actually have several inputs all called field?

GiacomoM's avatar

I need several input text boxes, i don't know how many, it depends on user's choice. I manage them with angularjs.

willvincent's avatar

If you're managing it with Angular, then Angular should be managing all of the logic between your form and the backend. Presumably a group of n fields, should be rendered with an ng-repeat on the angular side..

GiacomoM's avatar

I already do it. But I need a server validation either.

Pendo's avatar

Doesn't the dot notation work? Like

{{ old('field.0') }}

if not, that would be a good addition to Laravel I guess.

Pendo's avatar
Pendo
Best Answer
Level 10

Did a test, and the dot notation works.

{{ var_dump(old('field.0')) }}
<form method="post" action="">
    {!! csrf_field() !!}
    <input type="text" name="field[]" value="{{ old('field.0') }}" />
    <input type="text" name="field[]" value="{{ old('field.1') }}" />
    <input type="text" name="field[]" value="{{ old('field.2') }}" />
    <input type="submit" name="submit" value="Submit" />
</form>

field.0 returns anything you entered in the first input field.

23 likes
GiacomoM's avatar

Thanks, I will try and I will answer to you.

Even if I don't know why you use "veldnaam[]" and old('field.0')

Pendo's avatar

That's a typo in the sample, I did it in my native language while testing. It should be field[]

zymawy's avatar

Think You @Pendo It's Worked I Was Thinking That May Dot Notation Would Worked But Didn't Try It

akhil5570's avatar

On your blade use like this.

                          @if(old('field'))
                            @for( $i =0; $i < count(old('field')); $i++)                            
                           < input type="text" value="{{ old('field.'.$i)}}"  name="field[]" class="form-control" />                                       
                           @endfor
                          @endif
3 likes

Please or to participate in this conversation.