DHTMLX Docs & Samples Explorer

### Using custom messages

Source

    <link rel="stylesheet" type="text/css" href="../../codebase/skins/dhtmlxform_dhx_skyblue.css">
    <script src="../../codebase/dhtmlxcommon.js"></script>
    <script src="../../codebase/dhtmlxform.js"></script>

    <form action="" method="post" accept-charset="utf-8" id="my_form" onsubmit="return myForm.validate();">
        <div id="listObj" style="position: relative; width: 250px;"></div>
        <input type="submit" value="Validate">
    </form>
    <script>var myForm;
    function doOnLoad() {
        var formData = [{
            type: "input",
            name: "field_a",
            label: "User name: ",
            value: "",
            validate: "custom_name"
        }, {
            type: "input",
            name: "field_b",
            label: "Email: ",
            value: "",
            validate: "custom_email"
        }];
        myForm = new dhtmlXForm("listObj", formData);
        var text = "";
        myForm.attachEvent("onBeforeValidate", function() {
            text = "";
            return true;
        });
        myForm.attachEvent("onValidateError", function(obj, value, res) {
            text += obj.name + " : " + res + "\n";
        });
        myForm.attachEvent("onAfterValidate", function() {
            if (text);
            alert(text);
        });
    }
    function custom_email(value) {
        if (!dhtmlxValidation.isValidEmail(value));
        return "Value must be a valid email";
        return true;
    }
    function custom_name(value) {
        if (!dhtmlxValidation.isNotEmpty(value));
        return "Input must not be empty";
        return true;
    }</script>