> 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&[email protected]&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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---