don't worry, it's a mistake you'll probably never do again :P

On Saturday, December 21, 2013 11:27:13 AM UTC+1, Ivo wrote:
>
> I got it resolved... ashamed to say it but I missed the = in 
> the {{form.custom.end}} tag :(
>
> On Friday, December 20, 2013 3:16:34 PM UTC+1, Ivo wrote:
>>
>> I have chosen to go the custom form way.
>> The only issue I have is that upon hitting submit, the button submits all 
>> the forms on the page instead of just the one owning the button. I think 
>> this also screws up my validation and it prevents records from being 
>> inserted to the db.  
>>
>> controller:
>> def show_form():
>>     
>>     users_1 = 
>> db(db.people.id.belongs(session.people.keys())).select(db.people.user_id)
>>     users_2=[]
>>     for user in users_1:
>>         if user not in users_2:
>>             users_2.append(user)
>>         else:
>>             pass
>>
>>     forms=[]  
>>     for user in users_2:
>>         usr= db(db.auth_user.id
>> ==user.user_id).select(db.auth_user.username,db.auth_user.id)[0]
>>         usr1=usr.username
>>         usr2=usr.id
>>         key=str(usr2)
>>         fields = [
>>                   Field('key',default=key,writable=False),
>>                   Field('username',default=usr1,writable=False),
>>                   Field('address',default='Fill in your 
>> address',type='text')
>>                   ]
>>
>>         form=SQLFORM.factory(*fields, 
>> table_name=key,hidden=dict(ss_id=key),
>>                                              buttons=[
>>                                                   BUTTON("Save Changes", 
>> _class="btn btn-primary")])
>>         if form.process(formname=key, hideerror=True).accepted:
>>             db.parking.insert(name=usr1, address=form.vars.address)
>>         forms.append(form)
>>     
>>     return dict(forms=forms)
>>
>>
>>
>> view:
>> {{for form in forms:}}
>> {{=form.custom.begin}}
>> User: {{=form.custom.widget.username}} <br>
>> Address: {{=form.custom.widget.address}} <br>
>> {{form.custom.end}}<br><br>
>> {{pass}}
>>
>>
>> On Wednesday, December 18, 2013 9:45:14 PM UTC+1, Niphlod wrote:
>>>
>>> form.process adds little bits to the form to be able to actually process 
>>> the posted data.
>>>
>>> in pseudo-code you need to
>>>
>>> list_of_forms = []
>>> for something in list_of_values:
>>>      key = something_unique
>>>      form = SQLFORM(....)
>>>      if form.process(formname=something_unique).accepted:
>>>            .....code dealing with the posted values, such as form.vars, 
>>> etc
>>>      elif form.errors:
>>>            .....code dealing with form errors
>>>
>>>      list_of_forms.append(form)
>>>     ......
>>>     return dict(list_of_forms=list_of_forms, ....)
>>>
>>> In the view, you can then:
>>>
>>> {{for single_form in list_of_forms:}}
>>> <div class="row">
>>> {{=single_form}} #or {{single_form.custom.etc etc etc}}
>>> </div>
>>> <hr />
>>> {{pass}}
>>>
>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to