views:

176

answers:

1

I have an HTML form that a user can add an arbitrary amount of input fields to through jQuery. The user is also able to remove any input field from any position. My current implementation is that each new input box has an id of "field[i]" so when the form is posted it is processed in Python as field1, field2 field3, ...field[n]

i = 0
while self.request.get("field" + str(i)):
        temp = self.request.get("field" + str(i))
        someList.append(temp)
        i += 1

(Assume the JavaScript handles removing of deleted elements and sorts the field names prior to post for simplicity)

This approach is working for me, but is there a better way to handle this situation? I feel like this is a very brute force method.

Platform information: Python 2.5.4; JavaScript; DHTML; jquery; Google App Engine

Edit: It appears that self.request.get_all() was the solution: GAE Doc

+1  A: 

You could serialize the data with javascript and pass it in as json. Then you would just have a dictionary to work with in python. You would need something like simplejson, of course

Alex Sexton
I am using simplejson for other things currently. I'll look into this.
Jason Rikard