Yes this is ideal but I didn't think that would be possible to implement, 
because with this way the amount of columns would vary with each row and I 
am unsure of how possible it is to make it work because of that

On Wednesday, March 2, 2016 at 5:12:06 AM UTC-5, Dave S wrote:
>
>
>
> On Tuesday, March 1, 2016 at 7:33:38 PM UTC-8, [email protected] wrote:
>>
>> That makes so much sense! Thank you for explaining this to me, I did that 
>> and it finally works!
>>
>> I also changed the variable name to be nums to make things clearer as 
>> well.
>>
>> I am having trouble with inserting the items accordingly in the database, 
>> attached is a photo of a form submission I just did after filling out 3 
>> form instances in one session.
>>
>> I think it is because of my forloop but I don't understand why. 
>> This is my code: 
>>
>>
>> def postform():
>>     nums = int(request.vars.nums)
>>     inputs = []
>>     update = db.post(request.args(0))
>>     for i in range(0, nums):
>>         inputs.append(db.post.patient.clone(name='%s_%s' % (
>> db.post.patient.name, i)))
>>         inputs.append(db.post.attime.clone(name='%s_%s' % (
>> db.post.attime.name, i)))
>>         inputs.append(db.post.age.clone(name='%s_%s' % (db.post.age.name, 
>> i)))
>>     form = SQLFORM.factory(Field('nums', readable=False, writable=False, 
>> default=nums),*inputs)
>>     if form.process().accepted:
>>         response.flash = 'Thanks! The form has been submitted.'
>>         for i in range(0,nums):
>>             db.post.insert(patient=form.vars['patient_%s' % i])
>>             db.post.insert(attime=form.vars['attime_%s' % i])
>>             db.post.insert(age=form.vars['age_%s' % i])
>>         redirect(URL('postlist'))
>>     elif form.errors:
>>         response.flash = 'form has errors'
>>     return dict(form=form)
>>
>>
>> I don't understand why the forloop would be generated 9 rows instead of 3?
>>
>>
> Shouldn't the 3 inserts be combined into 1, that sets all 3 fields?
>
> /dps
>
>  
>
>>
>> On Tuesday, March 1, 2016 at 5:33:14 PM UTC-5, Dave S wrote:
>>>
>>>
>>>
>>> On Tuesday, March 1, 2016 at 2:19:53 PM UTC-8, [email protected] wrote:
>>>>
>>>> What do you mean by passing it through url?
>>>>
>>>> I am obtaining the value that is entered using request.vars, if I 
>>>> wasn't passing the value then it wouldn't be creating the entered amount 
>>>> of 
>>>> form fields, and it does this correctly. It only raises this error when I 
>>>> try submitting the form, which is where I am confused.
>>>>
>>>>
>>> You have a manually created form in your HTML.  The action for this form 
>>> takes you to postform(), where you create an SQLFORM.factory form,
>>> using a dynamic number of inputs.  The action associated with *that* 
>>> form is again postform(), which looks for request.vars.name.  You need 
>>> to make sure the factory form has that field (it would be okay to make it a 
>>> hidden field, since the number shouldn't change).
>>>
>>> Or, perhaps have the first form controller be prepostform(), which does 
>>> nothing but record the number in the session. and then redirects to 
>>> postform(), which uses the number in the session to decide how many input 
>>> to build.
>>>
>>> One thing about both of these approaches is that once you've 
>>> successfully submitted the factory form, you're going to get a fresh copy 
>>> with the same number of inputs.  Unless you've set things up to retrieve 
>>> the values that were just entered into the DB, and present them back to the 
>>> doctor for verification and editing.
>>>
>>> As an aside, it looks odd to have a variable named "name" being used for 
>>> a count rather than a name-string.  In my own code, when I do that sort of 
>>> thing, I get confused during debugging.
>>>
>>> /dps
>>>
>>>

-- 
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/d/optout.

Reply via email to