Home > OS >  Flask WTForms how to prevent duplicate form submission
Flask WTForms how to prevent duplicate form submission

Time:11-23

I'm new to Flask.

Forms.py:

class NoteForm(FlaskForm):
    note = fields.TextAreaField("Note")
    add_note = fields.SubmitField("Add Note")

router.py:

add_note_form = forms.NoteForm()

template:

<div >
  {{ add_note_form.add_note}}
</div>

Now if I click the add note button multiple times in a very short time ,the form will be summitted for multiple times, especial when the page is loading slowly.

Is there anyway I can prevent duplicate form submission ?

CodePudding user response:

One way to do this is to disable the submit button after form is submitted

onClick="this.form.submit(); this.disabled=true; this.value='Saving…'; "

Another way would be to give you record an id and check for duplicate in the backend.

  • Related