Chris Berghoff
Chris Berghoff

Reputation: 31

Calling function after jquery.validationEngine.js onValidationComplete

I'm using the jquery.validationEngine and have it working on both my registration and login forms. I'm able to use javascript sourced from the comments here to hash the password field before it is sent to the server for additional hashing and saving to the database. However, I'm unable to call the hashing script and then get the form to continue submitting. Can anyone point me in the right direction?

Hashing Script:

function formhash(form, password, p) {
p.value = hex_sha512(password.value);
password.value = "";

Relevant Head for Validator: I just can't figure out what goes in place of the string of question marks. I've tried a number of different combinations and just can't seem to get it. The validation works, but the form submits without running my formhash script if validation passes.

<script>
jQuery(document).ready( function() {
    jQuery("#login").validationEngine('attach', 
    {onValidationComplete: function(form, status){
         if (status == true) {
             $("form#login").bind('submit', function(e) {
                  e.preventDefault();
              });
                   // your function or your action 
                   ???????????????????
              }
         }  
    });
</script>

Upvotes: 1

Views: 3417

Answers (2)

Robin Gomez
Robin Gomez

Reputation: 333

yeah Chris, onValidationComplete need an boolean

you need

$('#form1').validationEngine('attach', {
onValidationComplete: function(form, status){
    if (status) {                   
        startProgressBar();
        YouFunctionPreLoad();
        return true;

    }
}           
});

Upvotes: 0

Chris Berghoff
Chris Berghoff

Reputation: 31

Well, I figured it out, and thought I'd share for any one else learning all of this. Not much documentation on the validator, though my major problem was with the javascript. Note, I wanted the validator to stop the form if there was an error and was fine with my function submitting the form if the validation passed...

  1. Remove the bind statement and replace the question marks in my question with your function

    <script>
    jQuery(document).ready( function() {
    jQuery("#formID").validationEngine('attach',{
    onValidationComplete: function(form, status){
    if (status == true){
    YourFunction();}}});
    });
    </script>
    
  2. Use DOM methods of accessing the form variables and submitting the form, e.g.,

    function YourFunction() {
    var password = document.getElementById("password");
    document.forms["formID"].submit();
    }
    

    Worked for me. Hope this helps someone in the future!

Upvotes: 2

Related Questions