Form validation array not validating properly

Posted 2 years ago by jksukino

I have a dynamic form that i would want to validate.

in my view:

<?php
@for ($i = 1; $i < 4; $i++)
<div>
 <label for="title[{{ $i }}]" class="control-label">Title</label>
 <input type="text" name="title[{{ $i }}]">
  @if ($errors->has('step-title'.$i))
    <span class="help-block">
      <strong>{{ $errors->first('step-title'.$i) }}</strong>
    </span>
  @endif
</div>
@endfor 

in my controller:

$this->validate($request, [
  'title1' => 'required|alpha_dash',
  'title.*' => 'alpha_dash',
]);

The fields are dynamically added with jquery. The validation of title1 works fine but the validation with a wildcard doesn't. What am i missing here?

its possible to changing the syntax in the view from title[{{ $i }}] to title{{ $i }} and title[] all with the same result but no validation on the dynamic fields.

On a side note. Is it possible to pass the data to the db without using $input = $request->all(); but also with a wild card?

Please sign in or create an account to participate in this conversation.