You are viewing limited content. For full access, please sign in.

Question

Question

Compare two fields , if is correct enable the button get into to other page

asked on January 20, 2022

 

 

 

 

the problem is , how to evaluate an empty field, because what I am trying to do is that if the password is correct, I enable the button, this function does, but the strange fact is that when it is empty the field is enabled and it is correct because they are not the same have no value unless you enter the wrong password the button is hidden


 

 

 

0 0

Replies

replied on January 21, 2022 Show version history

Instead of doing this with calculation, I would use a custom parsley validator. Although calculations could be set up to prevent the issue like Matthew mentioned, I think a validator has a lot more flexibility.

For example, if you use a validator, you could make it so the form wouldn't submit even if the button was visible because it would fail validation unless the password fields matched.

In the code below, I have a "passwordInput" class set on the main input, and a "passwordConfirm" class set on the read-only field. I also included code to hide/disable the button in comments.

$(document).ready(function(){
  //$('#myButton').hide().prop('disabled',true);
  
  // assign validator to password field
  $('.passwordInput input').attr({
    'placeholder':'Enter your password',
    'type':'password',
    'data-parsley-passwordconfirmation':''
  });
});

// custom validator for password confirmation
window.Parsley.addValidator('passwordconfirmation', {
  validateString: function(value, requirement, field) {
    var password = $('.passwordInput input').val();
    var confirm = $('.passwordConfirm input').val();
    
    var correct = (password == confirm && confirm != '');
    //$('#myButton').toggle(correct).prop('disabled',!correct);
    
    return correct;
  },
  messages: {
    en: 'Incorrect password.',
  }
});

 

Now that being said, doing a password this way is not especially secure, especially since someone could inspect the page and find the comparison field.

However, if security isn't a concern and you're using a lookup to pull the password based on the username, then I think a better way would be with a stored procedure.

Instead of populating the form with a value someone could find, build a stored procedure in your database that accepts username and password as the parameters.

Then, have that procedure return a true/false or 0/1 value to say whether or not a match was found and pull that value into your form instead.

That way, you can have field rules to show/hide the button based on whether or not the stored procedure returns a good value and you don't have the password somewhere they can check.

4 0
replied on January 21, 2022

Bravo.  Well said @████████!

1 0
replied on January 21, 2022

Thank you I aplicate your solution 

0 0
replied on January 21, 2022

It sounds like you might need to edit the formula in your check field.  In addition to checking that the two password fields match, you probably want to check that they are not empty or are over a minimum length.

1 0
replied on January 21, 2022

0 0
replied on January 21, 2022

This is my formula in the check field, which validates that they are the same but at the moment that it is empty by logic they are the same and it enables the field, I am checking the js of the partner that I commented on but I cannot execute it

Apart from the moment of filling in the user, the password is filled in the password2 field, from there I make the comparison of fields, and they are not the same that the field is not enabled and if the passwords are the same, it is activated

0 0
replied on January 21, 2022

the information is fill of my database 

0 0
replied on January 21, 2022

Ultimately, @████████'s suggestion is going to be much more secure.

But if you want to continue with the formula as you have it, you should be able to modify like this to check for blank fields:

=IF(Contrasena="", "NO", IF(Contrasena2="", "NO", IF(Contrasena=Contrasena2,"YES","NO")))

To get that YES value, both fields cannot be blank and must equal each other.

1 0
replied on January 21, 2022 Show version history

Thank you for the exmaple im new in forms :)

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.