0

I have a form with many fields with the same name, this will be an array input for PHP.

<input type="text" name="user[]" required />

Unfortunately it seems that Jquery validator, used on entire form, ignores consecutive inputs with the same name and it validate only the first one.

Take a look at this example:

<form class="validation-form">
    <lable>User1</lable>    
    <input type="text" name="user[]" required /><br>
    <lable>User2</lable>
    <input type="text" name="user[]" required /><br>
    <button class="submit-form">submit</button>
</form>

https://jsfiddle.net/xr5a03qf/

If you push on submit, you will se only the first required field is checked, if you fill just the first one, the form will be submitted as valid.

Is this a bug?

4
  • This question appears to have a solution: using jquery validate with multiple fields of the same name Commented Aug 18, 2022 at 10:50
  • So is not possibile to use attribute only? Commented Aug 18, 2022 at 13:24
  • The answer on that question suggests that jquery validate caches the names and only applies the validation to the first. This appears to be a specific decision rather than a bug. You can either remove the cache line from jquery-validate or add new rules by looping the inputs yourself. Both solutions provided on the question linked above. Commented Aug 18, 2022 at 14:26
  • Yes, that's how it works as verified in the documentation. The name on each field must be unique. Otherwise, only the first element matching the name is validated and the rest are ignored. Commented Aug 22, 2022 at 22:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.