I don't know what your database schema is, but if checkboxes are a
list, could the problem be that you are trying to insert a list into
one field? I think instead you should be iterating over that list and
doing one db.insert statement for each member of the list:
def POST(self):
i = web.input(groups = [])
for checkbox in i.groups:
db.insert("users", email = i.email, name = i.name, groups = checkbox)
I forget if an unchecked box in a POST request is returned as "False"
or if the key is not returned at all. If it returns "false", you'll
probably want this instead:
def POST(self):
i = web.input(groups = [])
for checkbox in i.groups:
if checkbox:
db.insert("users", email = i.email, name = i.name,
groups = checkbox)
-Jim
On Sat, Oct 22, 2011 at 3:16 PM, Tomás Acauan Schertel
<[email protected]> wrote:
> Sorry [email protected], but I didn't find any other message from this
> address.
> Jian, I have a form with three checkbox fields. Here they are:
>
> <input type="checkbox" name="groups"
> value="administradores"/>Administradores<br />
> <input type="checkbox" name="groups" value="operadores" />Operadores<br />
> <input type="checkbox" name="groups" value="usuarios"/>Usuários<br />
>
> I submit this form to a simple function that reads form's information and
> record this information to a database.
>
> def POST(self):
> i = web.input(groups = [])
> db.insert("users", email = i.email, name = i.name, groups =
> i.groups)
> raise web.seeother('/users/')
>
> When I submit the form, I get this error in browser:
>
> <class 'sqlite3.InterfaceError'> at /users/
> Error binding parameter 3 - probably unsupported type.
>
> Python /usr/lib/python2.7/site-packages/web/db.py in _db_execute, line 586
>
> And get this error in terminal:
> InterfaceError: Error binding parameter 3 - probably unsupported type.
>
>
> If I change this line "i = web.input(groups = [])" to "i = web.input(groups
> = {})", it partially works. Partially because I just get the value of the
> last checked checkbox and not all checkboxes.
>
> If I change db.insert to groups = str(i.groups), I get all values, but this
> inserts "[u'administradores', u'operadores']" to database.
>
> I'd like to see "administradores operadores" in database.
>
> If anyone could help me, I'd appreciate.
>
>
> --
> Tomás Schertel
> ----------------------------------------------
> Linux Registered User #304838
> Arch Linux User
> http://www.archlinux-br.org/
> ----------------------------------------------
>
>
> On Sat, Oct 22, 2011 at 13:05, <[email protected]> wrote:
>>
>> Hi Jian, i recently posted a working solution. Don't have good internet
>> access now, but search for my username in this forum and you'll find it.
>> ________________________________
>> From: Jian Chang <[email protected]>
>> Sender: [email protected]
>> Date: Sat, 22 Oct 2011 22:32:01 +0800
>> To: <[email protected]>
>> ReplyTo: [email protected]
>> Subject: Re: [webpy] Anyone using checkboxes in forms??
>> plz show some examples.
>>
>> 2011/10/21 Tomás Acauan Schertel <[email protected]>
>>>
>>> I still don't know how to use checkboxes in webpy.
>>> I always get just the value from last checked box .
>>>
>>>
>>> --
>>> Tomás Schertel
>>> ----------------------------------------------
>>> Linux Registered User #304838
>>> Arch Linux User
>>> http://www.archlinux-br.org/
>>> ----------------------------------------------
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "web.py" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/webpy?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "web.py" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/webpy?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "web.py" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/webpy?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "web.py" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/webpy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.