You can add custom code to a form by linking your Google Tag Manager (GTM) account with a form.
With GTM you can define your own snippets of code, and where and when they should execute. When linked with your forms this adds a very powerful layer of functionality and customizability.
Details on how to associate a GTM account with a form are here.
Note: The code you enter in your GTM account will run in the published version of the form only (not in the form editor view).