Hello. I am currently trying use WTForms, but I am encountering problems
I am using javascript to send an ajax post request instead of using the default form action for submit
$("#submit").click(function (e) {
e.preventDefault();
getLocationData(pushpin.getLocation()).then(function (result) {
let address = result.resourceSets[0].resources[0].name;
$.ajax("/", {
type: "POST",
data: {
name: $("#form #name").val(),
address: address,
phone: $("#form #phone").val(),
},
success: function () {
$("#form").submit();
},
});
});
});
But now, form.validate_on_submit() returns False
is_submitted() returns True but validate() returns False.
if request.method == "POST":
form = AddStudentForm()
if form.validate_on_submit():
flash('Student added!', 'success')
# ...
return redirect(url_for('index'))