I have a form that is similar to the following:
Enter Name:
Enter Age:
[add more]
That add more field copies the Name and Age inputs and can be clicked as many times as the user wants. Potentially, they could end up submitting 50 sets of Name and Age data.
How can I handle this received data when it's posted to my Pylons application? I basically need to do something like:
for name, age in postedform:
print name + ' ' + age
I've come across formencode's variabledecode function. But can't for the life of me figure out how to use it :/
Cheers.
You would post something like this (URL encoded, of course)
Do that for users 0-N where N is as many users as you have, zero-indexed. Then, on the Python side after you run this through
variabledecode
, you'll have:The values may differ depending on the validation you have going on in your schema. So to get what you're looking for, you would then do:
Update
To embed a list within an dictionary, you would do this:
So on and so forth. The pattern basically repeats itself:
{name-N}
will embed the Nth index in a list, starting with 0. Be sure that it starts with 0 and that the values are consecutive. A.
starts the beginning of a property, which can be a scalar, a list, or a dictionary.This is Pylons-specific documentation of how to use formencode, look at table 6-3 for an example.