0

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?

2
  • OK, I think I shouldn't add the array in the html. Commented Jul 27, 2010 at 9:12
  • I've been searching for a related issue for a while, now, and suggest that this question be edited so that it is more readily searchable / found. It took an IRC chat with an awesome individual in the #appengine room to link me to this question. Commented Oct 5, 2012 at 21:26

1 Answer 1

8

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)
Sign up to request clarification or add additional context in comments.

1 Comment

Nice, here's the relevant docs: webapp-improved.appspot.com/guide/request.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.