Validation for duplicated on form |
Hi i have a form with 20 serial number (serial_1 , serial_2 etc) , can i check with custom validation if there are duplicate in form ?
If you create an array of your serial numbers like serial[1], serial[2] etc. you can use the array_unique function to remove any duplicates from this array. Then count the number of items in the original array and compare it to the number of items in the array_unique array. If it differs, you know there were duplicates
(06-16-2023, 01:26 AM)JustJohnQ Wrote: If you create an array of your serial numbers like serial[1], serial[2] etc. you can use the array_unique function to remove any duplicates from this array. Then count the number of items in the original array and compare it to the number of items in the array_unique array. If it differs, you know there were duplicates Sorry but only serial_1 is required...
Then I don’t understand your question. What do you want to check for duplicates?
Validation of serial_1 is a simple validation. Checking all serials for a duplicate value is what I gave a suggestion for.
(06-16-2023, 02:38 PM)JustJohnQ Wrote: Then I don’t understand your question. What do you want to check for duplicates? Yes , i want control if there are a duplicate in one or more serial.... I can do it by js but i want also server side
array_unique is a php function. A custom rule like this will probably work:
See: https://codeigniter4.github.io/userguide...stom-rules PHP Code: <?php
(06-19-2023, 04:02 AM)JustJohnQ Wrote: array_unique is a php function. A custom rule like this will probably work: How can i pass in validation the array with every serial of form ? |
Welcome Guest, Not a member yet? Register Sign In |