Fix form handling for user feedback

issue was noticed on demo site, but possibly existed elsewhere?  also not 100%
sure about this fix, but it's believed to be okay...
This commit is contained in:
Lance Edgar 2019-08-04 22:14:15 -05:00
parent 287464362e
commit fda7230bce
2 changed files with 14 additions and 12 deletions
tailbone/forms

View file

@ -918,16 +918,13 @@ class Form(object):
if self.request.method != 'POST':
return False
# we assume data is in the form of POST params
controls = self.request.POST.items()
# but if not, we can try to parse request body as JSON
if not controls:
try:
controls = self.request.json_body.items()
except ValueError:
# not a valid JSON body, so no data
controls = []
# use POST or JSON body, whichever is present
# TODO: per docs, some JS libraries may not set this flag?
# https://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request.is_xhr
if self.request.is_xhr:
controls = self.request.json_body.items()
else:
controls = self.request.POST.items()
dform = self.make_deform_form()
try: