On Aug 2, 9:19 pm, mattynoce <mattyn...@gmail.com> wrote:
> hi, i have a question about hidden fields.
> i have a form that looks like this:
> fields=['f1','f2','f3'...]
> hidden=dict(fieldname=val)
> form = SQLFORM(db.table, fields=fields, showid=False, hidden=hidden)
> in the view it's simply {{=form}}
> when i look at the view, there's a hidden input field for my hidden
> field. however, when i do the insert, the hidden field is not getting
> inserted into my db. the accept info is:
>     if form.accepts(request.vars,session):
>          session.flash='Added'
>          redirect(URL(r=request, f="function"))
> am i doing something wrong? why would the hidden field show up
> properly in the view but not update the db?

Hi Matt,

I didn't know about this functionality before as it's not a documented
option in the docstring for SQLFORM (or FORM), but I see it in the
manual now.

Looking at the code in sqlhtml.py, it seems that the hidden fields
aren't processed by SQLFORM itself...I guess this is a design rather
than a bug (the hidden fields would normally be for other things than
DB fields).

You have several options to achieve what you want, including:
(1) Process this field manually in the 'if form.accepts' part
(2) Don't pass the field as hidden to 'form' but instead use jQuery to
hide the row (default value can be set within model or by jQuery)
(3) Follow Massimo's suggestion:
db.table.hidden_field.writable = False
form = SQLFORM(db.table, fields=fields, showid=False, hidden=hidden)
db.table.hidden_field.writable = True
if form.accepts(request.vars,session):

Best Wishes,
Fran.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to