0

Good day !

I am using optimizely . But its general question.

I have form validation code,

$("#frmForm").validate({
    // Specify validation rules
    rules: {
      // The key name on the left side is the name attribute
      // of an input field. Validation rules are defined
      // on the right side
      email: {
        required: true,
        // Specify that email should be validated
        // by the built-in "email" rule
        email: true
      },
      password: {
        required: true,
        minlength: 5
      }
    },
    // Specify validation error messages
    messages: {

      password: {
        required: "Please provide a password",
        minlength: "Your password must be at least 5 characters long"
      },
      email: "Please enter a valid email address"
    },
    // Make sure the form is submitted to the destination defined
    // in the "action" attribute of the form when valid
    submitHandler: function(form) {

      form.submit();
    }
  });

I want to write some code as

$(window).trigger('theyClickedSubmit');

After form submission success.

Keep this in mind that I can not access jquery code which is written above. I just want to make it externally.

Can we do this ?

Thanks in advance.

  • You mean, An event when the `form` is successfully submitted to the server? – Guruprasad J Rao Jan 20 '17 at 11:43
  • No. Its not coming in that block. Any other alternative –  Jan 20 '17 at 11:49
  • No, form.submit(); before this line I mean –  Jan 20 '17 at 11:50
  • Your question is completely unclear. What exactly do you need to capture? Any code you put just above `form.submit()` will fire *after* the form has been validated but *before* it is submitted. Why don't you have access to the jQuery code? What is the problem? – Sparky Jan 20 '17 at 15:31

1 Answers1

0

I want to write some code as $(window).trigger('theyClickedSubmit')

You would "capture" a click with jQuery like this...

$('#myButtonID').on('click', function() {
    alert('button was clicked');
});

After form submission success.

Unless it was submitted via ajax and you have access to that ajax code, you would not have access to know it was submitted.

Keep this in mind that I can not access jquery code which is written above. I just want to make it externally.

We have no idea what this means and your question is completely unclear. What exactly do you need to capture? Any code you put just above form.submit() in the submitHandler will fire after the form has been validated but before it is submitted. Why don't you have access to this jQuery code?

If you cannot access the code, then there is very little you can do here, especially if that code is on some other page.

Sparky
  • 98,165
  • 25
  • 199
  • 285