I have the following form:
<label>One</label>
Product ID:<input type="text" name="productid[]" value="">
Product Quantity: <input type="text" name="quantity[]" value=""> <br>
<label>Two</label>
Product ID:<input type="text" name="productid[]" value="">
Product Quantity: <input type="text" name="quantity[]" value=""> <br>
<label>Three</label>
Product ID:<input type="text" name="productid[]" value="">
Product Quantity: <input type="text" name="quantity[]" value=""> <br>
<!-- there may be more inputs like above (users can create new inputs
as many as they want) // I have a jquery function to create new rows-->
<input type="submit" value="submit">
Now My question is how to validate the form using Codeigniter when I have input names like this- name="productid[]" instead of name="productid" in my form.
Usually I use to validate my form like this way but this time it won’t work for the form above.
How to validate it?
You would use the literal field names, with brackets:
This will run the validation on every field with that name. If you have to validate only a specific index, once again – use the literal field name (and specify the index in your HTML):
It’s all in the documentation for Codeigniter’s Form Validation class: