This one still has me stumped so I'm taking the liberty of adding some
more info to make it current in the discussions. As I noted in the
earlier post, the problem has to to do with CKEditor's image
insertion dialog somehow triggering a form submission. This is really
puzzling, because the link insertion dialog is nearly identical but
doesn't trigger a submit. Below is a modified version of the index
function with some write statements to print the request vars and
session formkeys.
Any help much appreciated!
def index():
form = SQLFORM(
db.page, showid=False,keepvalues=True)
sys.stderr.write("\n\nsession formkey:
%s"%session['_formkey[page_create]'])
sys.stderr.write("\nrequest.vars:%s"%repr(request.vars))
if form.accepts(request.vars,session):
response.flash = "Form accepted"
redirect(URL(r=request,f="show"))
elif form.errors:
response.flash = "Uh-oh!"
else:
response.flash = "Fill out the form"
sys.stderr.write("\n%s\n"%response.flash)
return dict(form=form)
So when I visit the index page and use the CKEditor to insert a link,
I see the following output in the console.
(initial display)
session formkey:bf5ec584-0ec9-4e74-90ff-ba53971ea2f5
request.vars:<Storage {}>
Fill out the form
(after inserting link, clicking ok to insert dialog, then clicking
submit)
session formkey:f95327b1-6152-4fb3-abd2-00444c9cc298
request.vars:<Storage {'body': '<p>\r\n\t<a href="
http://web2py.com/
book/static/tree.jpg">link</a></p>\r\n', '_formkey':
'f95327b1-6152-4fb3-abd2-00444c9cc298', '_formname': 'page_create'}>
If I try the same thing except that this time I insert an image, I
get an extra submit and the session formkey gets out of sync with the
request.vars formkey.
(initial display)
session formkey:76e5e1fe-365c-401d-aaac-f2a751c8873e
request.vars:<Storage {}>
Fill out the form
(after inserting image and clicking ok in dialog)
session formkey:a143b2f1-bc5c-41b0-90e6-ef01fdc8e913
request.vars:<Storage {}>
Fill out the form
(after clicking Submit)
session formkey:9ee58f15-c1cd-4fa1-8766-b69b9a4478ac
request.vars:<Storage {'body': '<p>\r\n\t<img alt="" src="http://
web2py.com/book/static/tree.jpg" style="width: 401px; height: 500px;
" /></p>\r\n', '_formkey': 'a143b2f1-bc5c-41b0-90e6-ef01fdc8e913',
'_formname': 'page_create'}>
Fill out the form
The formkeys don't match, so form.accepts fails and the data never
gets into the table.
Thanks,
Mike