Welcome Guest, Not a member yet? Register   Sign In
validating multi-dimensional arrays
#3

[eluser]datdesignguy[/eluser]
JP,

I ended up solving the problem by simply renaming my form elements. It's a lot easier to just dump the multi-dim array if possible, due to the way that CI provides access to the values of fields with errors. At least that's my experience. I'm still working with the 1.5.4 codebase, so I don't know if that's changed much in the 1.6.x releases.

Using a fairly simple javascript, my form dynamically adds additional fields to the form, so all I had to do for the validation phase was maintain a hidden field that keeps track of the id numbers of each field that javascript/dom adds to the form.

IE, the first contact item in my list would be:

contact_1_firstname, contact_1_lastname, etc.

then if the user adds a second contact field to the form:

contact_2_firstanme, contact_2_lastname, etc.

The unfortunate thing about this approach is when I use a foreach loop to re-display each of these fields on an error form, I have to create a list of the values like so:

$fname = "contact_$i_firstname";
$lname = "contact_$i_lastname";

So that the validation class can redisplay the class:

$this->validation->$fname;

This feels like a really sloppy solution to me, and I too am still waiting to hear from other Igniters to see what they think...


Messages In This Thread
validating multi-dimensional arrays - by El Forum - 03-20-2008, 04:20 PM
validating multi-dimensional arrays - by El Forum - 04-02-2008, 09:55 AM
validating multi-dimensional arrays - by El Forum - 04-02-2008, 11:13 AM
validating multi-dimensional arrays - by El Forum - 04-02-2008, 04:52 PM
validating multi-dimensional arrays - by El Forum - 04-02-2008, 05:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB