Skip to content

Commit

Permalink
issue #178 - have JS forms POST as JSON instead of urlencoded
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Mar 23, 2018
1 parent 4509920 commit 8d14f24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion biweeklybudget/flaskapp/static/js/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function handleForm(container_id, form_id, post_url, dataTableObj) {
$.ajax({
type: "POST",
url: post_url,
data: data,
data: JSON.stringify(data),
dataType: "json",
contentType: "application/json",
success: function(data) {
handleFormSubmitted(data, container_id, form_id, dataTableObj);
},
Expand Down
5 changes: 4 additions & 1 deletion biweeklybudget/flaskapp/views/formhandlerview.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def post(self):
'success' -> boolean
'success_message' -> string success message
"""
data = request.form.to_dict()
data = request.get_json()
if data is None:
# not JSON, must be form encoded
data = request.form.to_dict()
res = self.validate(data)
if res is not None:
logger.info('Form validation failed. data=%s errors=%s',
Expand Down

0 comments on commit 8d14f24

Please sign in to comment.