Reputation: 9
My HTML code as following:
<INPUT type="text" name="txt[]">
<INPUT type="checkbox" name="chk[]"/>
I get the value in PHP by
<?php
$chkbox = $_POST['chk'];
$txtbox = $_POST['txt'];
foreach($txtbox as $a => $b)
echo "$chkbox[$a] - $txtbox[$a] <br />";
?>
How do get the value in Google App Engine using Python?
Upvotes: 0
Views: 1388
Reputation: 13629
You don't need that trick in Python. You can have for example many fields with the same names:
<INPUT type="text" name="txt">
<INPUT type="text" name="txt">
<INPUT type="text" name="txt">
<INPUT type="checkbox" name="chk">
<INPUT type="checkbox" name="chk">
<INPUT type="checkbox" name="chk">
Then get a list of all posted values for those names and merge them using zip()
. Example for webapp (which uses webob as request wrapper):
txt = self.request.POST.getall('txt')
chk = self.request.POST.getall('chk')
for txt_value, chk_value in zip(txt, chk):
print '%s - %s<br />' % (txt_value, chk_value)
Upvotes: 8