Thanks Massimo- I'm starting to understand the http flow better now... but the code you sent returned the same error I was seeing in my code when I clicked on the submit button on the form. Here are the snippets from the traceback: ... if form.accepts(request.vars,session): ... File ".../web2py/gluon/validators.py", line 70, in __call__ match = self.regex.match(value) TypeError: expected string or buffer
The URL I used was this: http://127.0.0.1:8000/my_app/input_data/form2?admin=False&email=...@s.com&name=j&profile=something&sure=yes And the controller code is this: def form2(): hidden = dict([(k,v) for (k,v) in request.get_vars.items() if not k in ['name','email','sure']]) form=FORM(TABLE(TR("Your name:",INPUT (_type="text",_name="name",_value=request.vars.name or '', requires=IS_NOT_EMPTY())), TR("Your email:",INPUT (_type="text",_name="email",_value=request.vars.email or '', requires=IS_EMAIL())), TR("Admin",INPUT(_type="checkbox",_name="admin")), TR("Sure?",SELECT ('yes','no',_name="sure",requires=IS_IN_SET(['yes','no']))), TR("Profile",TEXTAREA(_name="profile",value="write something here")), TR("",INPUT(_type="submit",_value="SUBMIT"))), hidden=hidden, action='POST', method=URL(r=request)) if form.accepts(request.vars,session): form.vars.update(hidden) # response.flash="form accepted" else: pass return dict (form=form,form_vars=form.vars,request_vars=request.vars) On May 29, 10:00 am, mdipierro <mdipie...@cs.depaul.edu> wrote: > You want: > ## receive info using URL params, and show the form > ## receive info using form when URL params present > ## show empty form when no URL params present > ## receive info using form when no URL params present > Do not do it this way because your point 2 is outsite the http specs > and different browsers will behave in different ways. > Some will discard the variables in the URL, some will not, some may > duplicate the values. This is not a web2py issue. This is a browser > issue. There is no standard. > > You should do > > def form(): > hidden = dict([(k,v) for (k,v) in request.get_vars.items() if not > k in ['name','email','sure']] > form=FORM(TABLE(TR("Your name:",INPUT > (_type="text",_name="name",_value=request.vars.name or '', > requires=IS_NOT_EMPTY())), > TR("Your email:",INPUT > (_type="text",_name="email",_value=request.vars.email or > '',requires=IS_EMAIL())), > TR("Admin",INPUT(_type="checkbox",_name="admin")), > TR("Sure?",SELECT > ('yes','no',_name="sure",requires=IS_IN_SET(['yes','no']))), > TR("Profile",TEXTAREA(_name="profile",value="write > something here")), > TR("",INPUT(_type="submit",_value="SUBMIT"))), > hidden=hidden, action='POST', method=URL(r=request)) > if form.accepts(request.vars,session): > form.vars.update(hidden) > else: > pass > > On May 29, 11:32 am, Dan <danbr...@gmail.com> wrote: > > > > 2) you are using > > > > form.accepts(request.vars,session): > > > > Which is desigend to prevent double submissions and various types of > > > attacks by hiding hidden one time tokens in the form and preventing > > > validation if the form if the token is not returned. > > > You can disable this by using > > > > form.accepts(request.vars,formname=None): > > > > and the request.vars.name will be copied in form.vars.name > > > Thanks for that suggestion, it helped a bit. > > > Sorry, I wasn't clear in my earlier message: I sent my code, and in > > addition to that I sent the URL to call one of the sample apps in the > > web2py documentation which showed the same symptoms. > > > Here is a self-contained example, with 3 different options for calling > > the "form.accepts()" method, each having slightly different problems/ > > symptoms - I need to get one of them working (or some other approach). > > The controller needs to be able to acecpt information from 2 different > > sources: either using parameters in the URL, or using a form on the > > web page. If the user starts out sending information using URL > > parameters, they should be able to use the form to send a subsequent > > set of information. > > That means the controller needs to do these 4 things: > > ## receive info using URL params, and show the form > > ## receive info using form when URL params present > > ## show empty form when no URL params present > > ## receive info using form when no URL params present > > > The URL with parameters that I'm using is this: > > http://127.0.0.1:8000/my_app/input_data/form?admin=False&emai...@s.com&name=j&profile=something&sure=yes > > and the URL without any parameters is of course > > this:http://127.0.0.1:8000/my_app/input_data/form > > > here is the code in the controller called input_data.py, mostly > > following the documentation's example 28 (http://www.web2py.com/ > > examples/default/examples): > > > def form(): > > form=FORM(TABLE(TR("Your name:",INPUT > > (_type="text",_name="name",requires=IS_NOT_EMPTY())), > > TR("Your email:",INPUT > > (_type="text",_name="email",requires=IS_EMAIL())), > > TR("Admin",INPUT(_type="checkbox",_name="admin")), > > TR("Sure?",SELECT > > ('yes','no',_name="sure",requires=IS_IN_SET(['yes','no']))), > > TR("Profile",TEXTAREA(_name="profile",value="write > > something here")), > > TR("",INPUT(_type="submit",_value="SUBMIT")))) > > > ### VALIDATION 1 (disabled) > > # if form.accepts(request.vars,session): > > ## receive info using URL params and show form: PROBLEM. > > information appears to be received but not processed. it says "please > > fill in the form" and the request variables are displayed (but not > > form variables). > > ## receive info using form when URL params present: ERROR. ("if > > form.accepts(request.vars,session):" leads to error "TypeError: > > expected string or buffer" from validators.py) > > ## show empty form when no URL params present: OK > > ## receive info using form when no URL params present: OK > > > ### VALIDATION 2 (enabled) > > if form.accepts(request.vars,formname=None): > > ## receive info using URL params and show form: OK > > ## receive info using form when URL params present: ERROR. ("if > > form.accepts(request.vars,formname=None):" leads to error "TypeError: > > expected string or buffer" from validators.py) > > ## show empty form when no URL params present: PROBLEM. shows user > > a "form is invalid" message > > ## receive info using form when no URL params present: OK > > > ### VALIDATION 3 (disabled) > > # if form.accepts(request.vars): > > ## receive info using URL params and show form: PROBLEM. > > information appears to be received but not processed. it says "please > > fill in the form" and the request variables are displayed (but not > > form variables). > > ## receive info using form when URL params present: ERROR. ("if > > form.accepts(request.vars):" leads to error "TypeError: expected > > string or buffer" from validators.py) > > ## show empty form when no URL params present: OK > > ## receive info using form when no URL params present: OK > > > response.flash="form accepted" > > elif form.errors: > > response.flash="form is invalid" > > else: > > response.flash="please fill the form" > > return dict > > (form=form,form_vars=form.vars,request_vars=request.vars) > > > So the issues that I'm trying to understand and fix: > > 1) when trying to receive info using form when URL params present, > > what does the error involving "expected string or buffer" mean? How > > can I fix that? > > 2) using validation method #2, how can I avoid showing the error > > message when the form is loaded without any parameters in the URL? > > 3) using validation method #1 or #3, why does the controllerappear to > > receive info from the URL but not act on it? > > > Thanks > > > Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" 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 -~----------~----~----~----~------~----~------~--~---