form validation where form vars are an array - 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 where form vars are an array (/showthread.php?tid=11996) |
form validation where form vars are an array - El Forum - 10-01-2008 [eluser]Unknown[/eluser] In my form I have named my inputs as so: <input type="text" name="guest[first_name]" /> <input type="text" name="guest[last_name]" /> <input type="text" name="guest[email]" /> With the validation library, they say to define fields like: $rules['first_name'] = "required"; $rules['last_name'] = "required"; $rules['email'] = "required"; So the problem is that when it goes to validate, it's expecting to find $_POST['first_name'], etc. So my question is, is there syntax to define a field where it is in a form array? (e.g. name="guest[first_name]"). I've tried: $rules['guest[first_name]'] = "required"; $rules['guest']['first_name'] = "required"; ...and neither worked. Any help appreciated! form validation where form vars are an array - El Forum - 10-01-2008 [eluser]Mirage[/eluser] Sometime in the past I believe to remember that someone wrote an adaption of the Validation library to support arrays. A forum or wiki search might reveal more information. I have use two methods to deal with this in the past: 1. Write a callback function which performs validation of the entire array and writes back the various results into the Validation instance. So in your case it would be a like callback_guest routine. 2. Flatten the form fields to something like: guest_first_name, and write rules against that. This option obviously requires that you do some post processing if you need to store this data in database, etc. HTH, -m form validation where form vars are an array - El Forum - 10-01-2008 [eluser]Yash[/eluser] Check out http://ellislab.com/forums/viewthread/51260 |