0

I am using laravel 6.10 on windows 7 (x64) wamp server (v 3.2.2.2).

I am validating 1 array input and 2 text inputs. I get validation error message in blade if array size is 84 or less than that. If i increase the array size to 85. I don't get any error message.

The validation function work as it redirect back if input is invalid but it doesn't show error message if array size is greater than 85. If input is valid, then no problem

here is blade

@if ($errors->any())
        <div class="alert alert-danger">
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif          
   <div class="flex-center position-ref full-height">
        <form method="post" action="{{url('form')}}" id="infoForm" >
            @csrf
            <input type="text" class="form-control" name="name" placeholder="Section A" value="{{ old('name') }}">
            <input type="text" class="form-control" name="king" placeholder="Section A" value="{{ old('king') }}">
            @for($i=0;$i<85;$i++)
                <input type="hidden" name="test[]" value="{{$i}}">
            @endfor
            <button type="submit">Submit</button>
        </form>         
    </div>

Controller

 public function store(Request $request)
{
    $validatedData = $request->validate([
        'name' => 'bail|required',
        'king' => 'bail|required',
        'test.*' => 'required'
    ]);
    dd('test');
    return redirect('form')->with('success', 'Information has been added');    
    
}

@dd(session()->all()) Result in blade if array size is less than 84

array:4 [▼
  "_token" => "s3kZaeGmEI9C7lNcH8mDLnzU0KNcXkO9luPeIzQa"
  "_flash" => array:2 [▶]
  "_old_input" => array:4 [▶]
  "errors" => Illuminate\Support\ViewErrorBag {#246 ▶}
]

@dd(session()->all()) Result in blade if array size is great than 84

array:3 [▼
  "_token" => "HjFH5QBSYaqnBAx8QG6PEGiIObueWYr6AjpVPolZ"
  "_previous" => array:1 [▶]
  "_flash" => array:2 [▶]
]

Is this a problem related to web server or related to laravel. Kindly help me to solve it. Here is the project on github https://github.com/mhabib555/LaravelMultipleInputWithSameNameValidation

Muhammad Habib
  • 350
  • 2
  • 14

4 Answers4

1

Check what you have for a session driver if it is a cookie as the default is on new projects, add this to your .env file

SESSION_DRIVER=file

Virus
  • 26
  • 2
0

I think the problem might be value set for post_max_size in your php.ini. Make sure to update this with higher value.

Also instead of:

'test.*' => 'required'

you probably want to add also:

'test' => ['array']

or maybe

'test' => ['array', 'required']

if there should be at least 1 item in test array to make sure test is an array.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • I set post_max_size to 0 ( as php.ini says: Its value may be 0 to disable the limit) in all php.ini files in wampserver but still i don't get error message in blade. And also removed test array from validation but still no error message in blade. – Muhammad Habib Jan 11 '20 at 09:39
  • @MuhammadHabib Make sure you restarted webserver as described here https://stackoverflow.com/questions/12892331/do-i-need-to-restart-apache-after-changing-the-php-ini-file/12892408 If it doesn't help try to add `dd($request->all());` before line with validation to see there are all data in there – Marcin Nabiałek Jan 11 '20 at 09:42
  • Already have restarted the server. I see all input when i use dd($request->all). The validation function also work as it redirect back if input is invalid but it doesn't show error message if array size is greater than 85. If input is valid, then no problem. – Muhammad Habib Jan 11 '20 at 09:53
0

Where your validation for the maximum array size ? Make sure you write it

Mohamed ِRadwan
  • 767
  • 2
  • 8
  • 17
  • I think i don't need maximum array size validation. My actual problem as stated in post is that i don't get error message (session flash) on blade if array size is greater than 84. If array is smaller than 84 then i get validation message (e.g name field is required). – Muhammad Habib Jan 12 '20 at 07:55
0

reproduced issue with array size 500

h4rDkur
  • 1
  • 3