form_validation library with input arrays - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: form_validation library with input arrays (/showthread.php?tid=33347) |
form_validation library with input arrays - El Forum - 08-23-2010 [eluser]coffeeandcode[/eluser] Hi all, I'm having difficulties getting ci's form_validation library to work with an input array I have. My variable is an array of text inputs containing product quantities, indexed by product id: Code: Array The problem is, ci requires that the EXACT variable name is used everywhere, and in my case that is dynamic. I can get it to validate when I use "quantities[]" as the variable name, but then I lose the product id. Am I missing something? I would think this would be a simple thing to do... form_validation library with input arrays - El Forum - 08-23-2010 [eluser]Jondolar[/eluser] Can you create a callback function when validating the quantities variable and then validate the individual array items yourself? I think I already had this issue and may have already solved this. I'll check when I get home. form_validation library with input arrays - El Forum - 08-24-2010 [eluser]coffeeandcode[/eluser] [quote author="Jondolar" date="1282620184"]Can you create a callback function when validating the quantities variable and then validate the individual array items yourself? I think I already had this issue and may have already solved this. I'll check when I get home.[/quote] I can, but I can only get it to match the variable if I put the product ids into the form validation config: Code: $config["orders/bulk"] = array( And then it treats them each as separate variables and validates them separately. This doesn't work because I want it to validate when the user has entered at least one product, of any id. ie, it should validate if one of the product quantities is greater than 0. I need it to be treated as a single variable. I also tried putting the ids and quantities into 2 different branches of a 2 dimensional array: Code: <input class="quantity" type="text" size="1" name="quantities[quantity][]" value="<?php echo set_value("quantities[quantity][]") ?>" /> and in this case it triggers the form validation properly, but it is still validating each array element separately. And it is a lot messier than what I was doing without the form validation library. Am I missing something? Is this not the way html input arrays are supposed to be used? Is there a cleaner way of doing what I'm trying to accomplish? |