Search code examples
javascriptajaxformsmootools

Mootools code for success, failure and submit


Does Mootools validation have a similar process for

Success, Failure and ajaxSubmitFile?

 $("#rems").validationEngine({
                    ajaxSubmit: true,
                    ajaxSubmitFile: "database/agentpanel/reminder/makerem.php",
                    success : function() { 
                        $.get("database/agentpanel/reminder/loadrem.php", function(html) {
                        $("#rem-scroll").html(html);
                        alert("Reminder Set");
                        $('#rems').find("input[type=text], textarea").val("");
                        $('#rem_confirm').attr('checked', false);
                        });
                    }, 
                    failure : function() { alert("Fill in all the fields with Red Marks"); }
                });

I would like to be able to send the form without going to the next page, and also run an script on success and on failure.


Solution

  • You can add event functions to Mootools Form Request.

    Try this:

    new Form.Request(myForm, myResult, {      
        onSend: function () {  // function to run on send
            alert('Will send now!');
        },
        onFailure: function (){//function to run if failure (fires after onComplete)
            alert('oops...!');
        },
        onComplete: function () {//function to run on send complete
            alert('Submited!');
        }, 
        onSuccess: function () {//function to run on success
            alert('Success!');
        },
        requestOptions: { //etc...
    

    Demo here

    Worth to read: