SEM Labs

Handcrafted Pixels, Code & Title Tags

Integer Replacement

XFL

When using the XFL foreach element to repeat sections of an XFL document, there may be cases in which you need to specify integer keys to group fields.

Example

XFL Document Fragment:

The above example would result in a post where the first set of braces ([]) increase by one each time like so:

staff[0][skills][0]
staff[1][skills][0]
staff[2][skills][0]
staff[3][skills][0]

However, you may need to group values with each iteration of the foreach element. To accomplish this, add a question mark inside the required braces like so:

With two iterations of the foreach element, posting to the form will now produce a post array like this:

staff[0][skills][0]
staff[0][skills][1]
staff[1][skills][0]
staff[1][skills][1]

An example of an integer replacement form can be seen here.