使用Webpad的CKEditor插件时表单提交错误

时间:2013-08-26 06:27:51

标签: forms web2py

我正在使用web2py的CKEditor插件。我遇到的问题是,在表单上,​​当有人点击下拉值时,表单是使用javascript提交的,request.vars中的id用于生成新的表单值(form.vars.body),该工作正常,直到代码到达form.accepts(req ...,sess ..)。由于某种原因,窗口小部件值(form.vars.body)在提交之前更改为原始值(其他form.vars字段更改并正常工作)。我的问题是form.accepts(req ..,ses ..)再次更改或调用窗口小部件代码中的任何内容,以将该特定字段恢复为其原始值。

query1 = db.contents.event_instance_id==event_instance_id
query2 = db.contents.section==section_id

contents = db(query1 & query2).select(db.contents.id, db.contents.title,db.contents.body).first()

record=contents.id
fields = ['id','section', 'title', 'body']

# get form
# this returns the correct form.xml with the right content for db.contents.body
form = SQLFORM(db.contents, record, fields=fields, submit_button=T('Save Content'))

if form.accepts(request.vars, session):
    response.flash = T("Contents saved")
elif form.errors:
    response.flash = T("Error saving content")

# but after form.accepts the form.xml is different, form.vars.body is different, 
# which is then passed to the view with the wrong content for the field with widget
return dict(form=form, title=title, event_instance_id=event_instance_id)

in the model

record=contents.id fields = ['id','section', 'title', 'body'] # get form # this returns the correct form.xml with the right content for db.contents.body form = SQLFORM(db.contents, record, fields=fields, submit_button=T('Save Content')) if form.accepts(request.vars, session): response.flash = T("Contents saved") elif form.errors: response.flash = T("Error saving content") # but after form.accepts the form.xml is different, form.vars.body is different, # which is then passed to the view with the wrong content for the field with widget return dict(form=form, title=title, event_instance_id=event_instance_id)

在视图中只有db.define_table('contents', Field('event_instance_id', 'reference event_instance', label='Event Instance'), Field('section', 'reference sections'), Field('title', length=255, requires=IS_NOT_EMPTY()), Field('body', 'text', requires=IS_NOT_EMPTY(), widget=ckeditor.widget) )

0 个答案:

没有答案