Validation hooks

onValidate()

Called prior to default Form validation. This is useful if you want to execute custom code prior to the Form being submitted, or if you want to do your own validation.

Returns:

bool|NULL|void Return TRUE to skip the default validation and continue with submitting the Form. Return FALSE to skip the default validation and prevent the Form submission. Return NULL to still proceed with default validation.

MauticFormCallback['formname'] = {
    onValidate: function () {
        var email = document.getElementById('mauticform_input_formname1_email').value;
        if (email.includes('@gmail.com')) {
            alert('Please use a work email address.');

            // return FALSE to stop the form submission
            return FALSE;
        }

        // return NULL|void to continue with default validation or return TRUE to skip it
    },
};
onValidateStart()

Called at the beginning of the default Form validation.

Returns:

void

MauticFormCallback['formname'] = {
    onValidateStart: function () {
        // do some custom stuff
    },
};

Note

This isn’t called if an onValidate() hook returns TRUE.

onValidateEnd()

Called after the Form has been validated by either the default validation or the onValidate hook.

Arguments:
  • isFormValid (bool()) – TRUE if the Form was successfully validated or FALSE if not.

Returns:

void

MauticFormCallback['formname'] = {
    onValidateEnd: function (isFormValid) {
        // do some custom stuff
    },
};
onErrorMark()

Called before updating a field’s element with a validation error.

Arguments:
  • fieldValidationObject (object()) –

    • fieldValidationObject.containerId The ID of the field’s container element.

    • fieldValidationObject.valid TRUE|FALSE

    • fieldValidationObject.validationMessage The error message.

Returns:

bool|NULL|void Return TRUE to skip the default behavior of appending the validation message to the field container’s element with the .mauticform-errormsg class.

var fieldValidationObject = {
    containerId: 'mauticform_formname_email',
    valid: FALSE,
    validationMessage: 'Email is required!'
};

MauticFormCallback['formname'] = {
    onErrorMark: function (fieldValidationObject) {
        if ('mauticform_formname_email' == fieldValidationObject.containerId && !fieldValidationObject.valid) {
             // do something custom
        }
    },
};
onErrorClear()

Called prior to clearing a field’s validation error.

Arguments:
  • fieldContainerId (string()) – The ID of the field’s container element.

Returns:

bool|NULL|void Return TRUE to skip the default behavior of clearing the validation message from the field container’s element with the .mauticform-errormsg class.

MauticFormCallback['formname'] = {
    onErrorClear: function (fieldContainerId) {
        if ('mauticform_formname_email' == fieldContainerId) {
             // do something custom
        }
    },
};