onWixFormSubmit( )


Adds an event handler that runs when a site visitor starts to submit a Wix Form yet before the form is actually submitted and sent to the server.

When a site visitor submits a Wix Form, the onWixFormSubmit() event handler runs for the WixForms element before the Wix Form data are submitted to the server.

The callback to run when the Wix Form that is about to be submitted is either the name of the function or a function expression.

The event handler can contain synchronous operations only. If you include asynchronous operations, no error is issued and the asynchronous operations are ignored.

Generally, define form validations and operations in one onWixFormSubmit() event handler.

Note: You can define more than one onWixFormSubmit(), for example, if you prefer to split your code into chunks. Keep in mind that all validations for all the event handlers must succeed for their operations to be performed and for the data to be sent to the server.

The event handler runs in parallel with any operations defined in an onClick() event handler.

Note: Do not explicitly include the onWixFormSubmit() inside an onCLick(). This is because onWixFormSubmit() must be loaded before an onClick() event handler runs.

The onWixFormSubmit() event handler does the following:

  • Performs built-in, general validations (such as checking that all email fields contain valid email addresses).

    These validations are performed without your needing to code them.

    If the form fields do not pass validation, the submission of the Wix Form data to the server is aborted.

  • Performs client-side, synchronous operations and validations that you define in the event handler.

    This gives you the opportunity to manipulate the data on the Wix Form before submitting the data for server processing. For example, the Wix Form might have first and last name fields, but the server might be expecting full names only. You can combine the first and last name into one field before sending the data to the server.

    These manipulations cannot include adding new fields or deleting fields. You can only change values of existing Wix Form fields.

  • Lets you stop the submission process entirely by returning a false value based on validations you define.

    If a WixFormSubmitEvent event fails, operations for all WixFormSubmitEvent event stop, no submission occurs, and console warnings are issued. You can use the onWixFormSubmitted() event handler to check if data for the Wix Form was successfully submitted to the server.

The received WixFormSubmitEvent object contains information about the Wix Form that is about to be submitted. The WixFormSubmitEvent object is returned by the callback asynchronously after a submit was requested, before the server receives the request, and before the server starts to process the relevant operations.

onWixFormSubmit() provides information and functionality available on the client side only:

  • The function has access to the field names and field values on the form but does not have access to submission details that exist only on the server, such as the contact ID and the submission time.
  • The function performs operations only on the client side, such as changing field values before submission to the server.

For other Wix Forms events, see:

  • The onWixFormSubmitted() event handler, which sets events that fire when a site visitor submits a Wix Form and it is successfully received by the server.
  • The onWixFormSubmittedError() event handler, which sets events that fire when a site visitor submits a Wix Form and it is not received by the server.
  • The onFormSubmit() event handler, which is called in the Backend section's code, to set events that fire on the backend when a site visitor submits a form.
Method Declaration
Copy
Method Parameters
eventHandlerfunctionRequired

eventHandler(event: WixFormSubmitEvent): object | boolean The name of the function or the function expression to run when a Wix Form is submitted.

Was this helpful?
Yes
No