On form submission error

Do something when a form fails to submit the entries (eg, there was a server error)

If a form submit event is triggered (by a user pressing a submit button or by submit being triggered programmatically) and the data submission fails (eg, due to the data being in the incorrect form) then we can run some custom code using the code example below.

JavaScript


Fliplet.Hooks.on('onFormSubmitError', function (error) {
  // Add your code to handle the error or do something else
});

The onFormSubmitError hook returns a function that has access to an error message that contains the following two properties:

  • formData – the data values that were originally submitted
  • error – an explanation of the error

In the example below, we’ve added some code that tells the user that there’s an error (by showing a ‘toast’ popup message ‘Error submitting form’) and asks them if they want to try to resubmit the data (by providing a button with the label ‘Retry’ on it. If the button is clicked the form data is resubmitted).

JavaScript


Fliplet.Hooks.on('onFormSubmitError', function (error) {
  // Try resending the form
  Fliplet.UI.Toast({
    message: 'Error submitting form',
    actions: [
      {
        label: 'Retry',
        action: function () {
          Fliplet.FormBuilder.get()
            .then(function (form) {
              form.instance.onSubmit();
            });
        }
      }
    ]
  })
});