I understand that I need to use different formnames, I just don't
understand how I would syntax it do that automatically.
A single form will not suffice; I think is has to be different forms. I
need a uuid for each user and create/update several records for each user.
Basically I need to use something like:
def show_form():
for user in users:
form= SQLFORM.factory()
return dict(form=form)
But then in a way that works. I tried several ways, but am still
unsuccessful...
I read (, re-read and re-re-read) the chapter on forms in 'the book' but
there's no mention on how to achieve something like this, neither in the
examples.
I tried digging through a lot of the sample apps too but nothing.
I understand this is not the basic way forms are designed to be used but is
it that uncommon to do this?
I also tried:
for user in users:
form[user]= SQLFORM.factory()
return dict(form[user]=form[user])
this throws a global name form is not defined.
I also tried:
for user in users:
form = SQLFORM.factory()
form[user] = form
any ideas?
On Tuesday, December 17, 2013 9:03:50 PM UTC+1, Massimo Di Pierro wrote:
>
> What does the model look like? You amy want to create a single form with
> fields for each user.
>
> On Tuesday, 17 December 2013 05:14:25 UTC-6, Ivo wrote:
>>
>> I want to create multiple forms with a 'for' statement and
>> validate/process them.
>> the amount of forms to generate is dependent on a list containing user
>> id's.
>> the list is dynamic; so I have a function generating a list, 'users',
>> which contains: user:1L, user:4L, etc...
>> now I want to create a form for each of them and after 'submit' process
>> them.
>>
>> Normally I would just create a form in the controller like:
>> def show_form():
>> form = SQLFORM.x()
>> return dict(form=form)
>> and process it with:
>> if form.accepts
>>
>> however this would only generate one form...
>> using:
>> def sow_form():
>> for user in users:
>> form = SQLFORM.x()
>> return dict(form=form)
>> and calling it from the view with {{=form}} doesn't work either because
>> of 'form' being static.
>>
>> Creating the form from the view is a lot easier to do with:
>> {{for user in users:}}
>> (my form)
>> {{pass}}
>>
>> but how do I process it?
>> I can give the form a unique name from the view with name="{{=user}}"
>> but then what?
>>
>> The form is mostly prepopulated with vars created/calculated from the
>> view but a part of those can be created/calculated from the controller.
>> the form requires a uuid which needed in the processing of the form.
>>
>> What is the best way to achieve this?
>> would:
>> def show_form():
>> for user in users:
>> form[user] = SQLFORM.x()
>> work? and how can I populate that form?
>>
>> Please point me in the right direction.
>>
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.