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 > On Friday, February 26, 2016 at 1:16:18 PM UTC-8, Richard wrote: >> >> You fall on an empty "name" vars... Could you have forget to pass the >> name vars throught url? >> >> Richard >> >> On Fri, Feb 26, 2016 at 3:14 PM, <[email protected]> wrote: >> >>> Can someone please tell me why I am getting this error and how to fix it? >>> >>> >>> numpatients = int(request.vars.name); >>> <type 'exceptions.TypeError'> int() argument must be a string or a >>> number, not 'NoneType' >>> >>> *db.py* >>> >>> >>> db.define_table('post', >>> Field('patient'), >>> Field('attime'), >>> Field('age') >>> ) >>> >>> *view.html* >>> >>> *index.html* >>> >>> <form enctype="multipart/form-data" action="{{=URL('default', >>> 'postform')}}" method="post"> >>> How many patients?: <input name="name"/> <input type="submit"/> >>> </form> >>> >>> >>> >>> *postform.html* >>> >>> {{=BEAUTIFY(form)}} >>> >>> >>> *controller.py* >>> >>> >>> def postform(): >>> inputs = []; >>> numpatients = int(request.vars.name); >>> for i in range(0, numpatients): >>> 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(*inputs) >>> if form.process().accepted: >>> for i in range(0,numpatients): >>> db.post.insert(post=form.vars['patient_%s' % i]) >>> db.post.insert(post=form.vars['attime_%s' % i]) >>> db.post.insert(post=form.vars['age_%s' % i]) >>> elif form.errors: >>> response.flash = 'form has errors' >>> return dict(form=form) >>> >>> >>> >>> >>> I want to prompt the user to enter a value of how many patients to enter >>> for the session, they are redirected to a page where a single form is >>> displayed and there are multiple form field instances displayed based on >>> the number of patients they want to enter for that session. When I click >>> submit after filling the form, I keep getting that error and I don't >>> understand why or how to change it because I need that value from the >>> previous page to know how many form field instances to display. >>> >>> -- >>> 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. >>> >> >> -- 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.

