JavaScript form submit listeners (technical)

The information on this page does not apply if forms are submitted programmatically.

Send2CRM needs to add a listener to forms to send to Salesforce prior to normal submission. In most cases this just happens, but sometimes other scripts may add their own handlers which fire first and cause Send2CRM functionality not to run.

By default, Send2CRM will attempt to capture form submissions (for specified forms only) using a listener on the form element submit event. The Send2CRM event listener must be the first attached for automated form functionality to operate correctly.

Send2CRM automatic form processing intercepts the form submission to send to Salesforce first. However it always completes normal form submission when successful, so all event listeners and normal form operation will apply.

Script order

If possible simply run the Send2CRM script before others that attach form submit listeners. Place it at the bottom of the <body> element before other scripts.

Alternatively, call Send2CRM code to ensure that the form is attached first:

// Attach automatic Send2CRM form processing (formElement is the <form> DOM element). send2crm.forms.processForm(formElement);

Submit on button

Where multiple listeners exist and the order cannot be guaranteed, Send2CRM offers an alternate automated mode that works when a submit element is present within the form:

  • Only applies if the formListenOnButton setting is enabled.

  • Works with the first [type="submit"] element within the form. May be a <button> or <input> element.

  • The submit element is cloned and hidden. The clone is changed to [type="button"] and Send2CRM processes the form on the click event.

  • After Send2CRM processing completes, the original (hidden) submit button is clicked to submit the form as normal.

Programmatic submission

If none of the above works for you, or you simply need more control, submit forms programmatically.

Â