Don't store form submission data

I’m using Netlify Forms for a contact form a site I built and it’s working very well.

For our use case, however, we don’t want the information being stored. We have Forms set up to send us an email with the form info, and after that, we’d like it to not persist in the Forms ‘verified submissions’ list.

Is there a way to have Forms not store submissions? Or perhaps some workaround, such as calling a webhook to delete the submission after other user actions (email notification, etc.) have occurred?

Hello @mfan, there is no setting to prevent our system from storing your Form submissions. However, you could use the API endpoint https://open-api.netlify.com/#operation/deleteSubmission to delete the form as they come in. Would that work for you?

Hi @Dennis, thanks for the reply.

That could work, yes. In order to do this, I’d have to create a Lambda function to respond to this event, correct?

yes, that is correct. You can learn more about functions here:

Did you ever get this to work with a function responding to the submission-created event? If so, I’d love to see the code. I’ve been pulling my hair out for days trying to get this exact thing to work. I can get it working locally with netlify dev and netlify-lambda but it never works (deletes the form submissions) deployed.

Hey @dazulu,
If you want to share what you have so far, we’d be happy to take a look!

At a high level, I think you’d need to set a personal access token as an environment variable in order to make the authenticated request from your function to the Netlify API. From within your function, you’d send that token in an auth header, accessing it with process.env.WHATEVER_YOU_CALL_THIS_VAR. Then, you’d make a GET request to https://api.netlify.com/api/v1/forms/FORM_ID/submissions. For each request returned, you’d send a DELETE request to https://api.netlify.com/api/v1/submissions/SUBMISSION_ID.

Maybe I’m sharing things you already know but just sharing how I’d get started :slight_smile: Let us know if this helps or where specifically you’re getting stuck and we’ll try to help.

@jen Hi Jen. Thanks for the reply! Your rundown sounds like the angle I had taken. I have a thread for the issue :sweat_smile: Function working locally, not when deployed

Thanks for sharing that @dazulu! I was able to build on your work and get a working form deletion function going. May be of interest to you too @mfan- function code in the thread above :slight_smile:

1 Like