def index():
if request.vars["getpdf"]:
response.headers["Content-Type"] = "application/pdf"
return ""
form = FORM()
form.append(INPUT(_name="addfield", _type="submit", _value="add field"))
form.append(INPUT(_name="getpdf", _type="submit", _value="get pdf"))
return dict(form=form)
def pdfcontroller():
if request.args(0) == "monthly": ...
# and/or:
if request.vars.some:
....
response.headers["Content-Type"] = "application/pdf"
return pdfcontent
if form.process().accepted:
redirect(URL("pdfcontroller", args=[form.vars.report_type], vars = dict(month = form.vars.month, anothervar= form.vars.somevar)))
A ("get pdf ", _href = URL(...))
It's unexpectedly, that the form is still alive after "getpdf", because the controller doesn't return any form (unless it's an ajax-request).
I think, If you want to return a pdf that depends on some args/vars then better to have the separated controller: [...]
response.headers["Content-Disposition"] = 'attachment'
AnthonyThis a bug -- I just submitted a pull request to fix it: https://github.com/web2py/web2py/pull/1746.
For now, you can make that same change in your own web2py.js.
Also, technically, the code you have shown below does not actually result in a problem because the "Content-Disposition" of the file is not set to "attachment", so the browser simply displays the (empty) PDF in place of the original page before the buttons are re-enabled.