# On form submission error

**URL:** <https://community.fliplet.com/t/on-form-submission-error/384>\
**Category:** Code Library\
**Created:** [July 6, 2022, 2:58pm UTC](https://community.fliplet.com/t/on-form-submission-error/384 "2022-07-06T14:58:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaberlem](https://avatars.discourse-cdn.com/v4/letter/a/9e8a1a/32.png) [@aaberlem](https://community.fliplet.com/u/aaberlem)\
**Post date:** [July 6, 2022, 2:58pm UTC](https://community.fliplet.com/t/on-form-submission-error/384/1 "2022-07-06T14:58:58Z")

</div>

**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**

```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**

```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();
            });
        }
      }
    ]
  })
});

```
