6

I have a form which have multiple select dropdown name=select[], and this form is validate from Jquery Validation and after successful validation Submit handler call Ajax i want to send all form keys and values also include in array form , Here is My Code .

function:submitHandler
{
$.ajax({
url: "processo.php", 
type: "POST",             
data: new FormData(this),
cache: false,             
processData:false,      
success: function(data)   
{
$('#loading').hide();
$("#message").html(data);
}
});
}

Now the when validation successfully done new FormData(this) not recognize form id.but when i put new Formdata($("#frmRegister")[0]) then its send variables to php but not array. How can i define form id in like new Formdata("#frmRegister").Remember please i also have mulitple select array in form .

1
  • Where is the rest of the code? Why function: submitHandler? Within the .validate() method, it should be submitHandler: function(form) {...}. Show the rest of the relevant code in proper context. Commented Mar 12, 2017 at 15:50

2 Answers 2

17

The submithandler goes inside of the .validate() method and you would use the form argument provided by the developer.

$('#myform').validate({
    submitHandler: function(form) {
        $.ajax({
            url: "processo.php", 
            type: "POST",             
            data: new FormData($(form)),
            cache: false,             
            processData: false,      
            success: function(data) {
                $('#loading').hide();
                $("#message").html(data);
            }
        });
        return false;
    },
    // other options
});

You could also use $(form).serialize(); instead.

Sign up to request clarification or add additional context in comments.

Comments

1

Thank You Very Much For giving Answer i have solution here is code .

function: submitHandler {
            $("#frmRegister").load("submit", function (e)// Trigger Submit When Validation Done
            {
                $.ajax({
                    url: "processo.php",
                    type: "POST",
                    data: new FormData(this),
                    cache: false,
                    processData: false,
                    success: function (data) {
                        $('#loading').hide();
                        $("#message").html(data);
                    }
                });
            });
        }

3 Comments

But where is function:submitHandler{...} located?? None of this is making any sense within the context of the jQuery Validate plugin. Are you actually using this plugin as indicated by the tag on your question?
sorry , but function:submitHandler dose not exist should be submitHandler: function(form) as your request .Thanks
If that's true, then $("#frmRegister").load("submit") makes less sense. You would never put a load handler or submit event within the submitHandler callback function for this plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.