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.
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?
I need several input text boxes, i don't know how many, it depends on user's choice. I manage them with angularjs.
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..
I already do it. But I need a server validation either.
Doesn't the dot notation work? Like
{{ old('field.0') }}
if not, that would be a good addition to Laravel I guess.
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.
Thanks, I will try and I will answer to you.
Even if I don't know why you use "veldnaam[]" and old('field.0')
That's a typo in the sample, I did it in my native language while testing. It should be field[]
Think You @Pendo It's Worked I Was Thinking That May Dot Notation Would Worked But Didn't Try It
How can we get the last element in the array
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
@akhil5570 I created my account just to thank you man
Please sign in or create an account to participate in this conversation.