POST多个复选框值tornado [英] POST multiple checkbox value tornado

查看:734
本文介绍了POST多个复选框值tornado的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用一个龙卷风网络应用程序,我需要一点帮助。我有多个具有相同名称的复选框,我想POST所选择的值。

I am messing around with a tornado web app with which I need a bit of help. I have multiple checkboxes with the same name and I would like to POST the values of the selected one.

<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>
<input id=DB_BASED_ID name="activity" value=DB_BASED_ID type="checkbox"/>

我可以使用javascript之前获得每个的值,但是我遇到了麻烦, python(龙卷风)侧。我只能得到最高的选择值。

I can get the values of each with javascript pre-POST but am having troubles getting this list on the python (tornado) side. i only get the highest selected value.

在python一边看起来像:

on the python side it looks like:

...

def post(self):
    email = self.get_argument("email")
    activity = self.get_argument("activity")


推荐答案

多个标签具有相同的名称属性,但 id DB_BASED_ID 的出现以某种方式被替换为一个不同的值?为什么不显示事实实际上不同,因为他们确实出现在真正的HTML?!),使这个无效的HTML和受到各种各样的问题。

It's fine to let multiple tags have the same name attribute, but the id attributes must be unique -- here, they're not (unless each of those occurrences of the identical DB_BASED_ID is somehow meant to be replaced with a different value? But then why not show the things actually distinct, as they do appear in the real HTML?!), making this invalid HTML and subject to all sorts of problems.

一旦这个问题被解决,在这些处理程序方法中, self.request.arguments ['activity'] (如果该字符串键存在于所述目录中)是所有输入'activity'(如果有)的非空值列表。

Once this problem is fixed, in those handler methods, self.request.arguments['activity'] (if that string key is present in said directory) will be a list of non-empty values for all inputs named 'activity' (if any).

这篇关于POST多个复选框值tornado的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆