Google App engine - submitting form field "field[key]" [duplicate]
So my question is, how I can get form values as list when submitting this particular form:
<form action="/foobar" method="post">
<input type="text" value="text 1" name="text[key_1]" />
<input type="text" value="text 2" name="text[key_2]" />
<input type="text" value="text 3" name="text[key_3]" />
<input type="text" value="text 4" name="text[key_4]" />
</form>
Currently, you cannot get all this values as dict / touple / list using self.request.get('text') or self.request.get_all('text'), cause this only works if you exactly specify self.request.get('text[key_1]').
You can do this type of f开发者_JAVA技巧orm:
<form action="/foobar" method="post">
<input type="text" value="text 1" name="text" />
<input type="text" value="text 2" name="text" />
<input type="text" value="text 3" name="text" />
<input type="text" value="text 4" name="text" />
</form>
texts = self.request.get_all('text') // you would get texts = ['text 1', 'text 2', 'text 3', 'text 4']
But like I said, I need key/pair form values
I guess you are using webapp framework. To get key/value pairs. you can do something like this
if your method is GET,
self.request.str_GET.items()
else
self.request.str_POST.items()
More reference here
精彩评论