Developer forum

Forum » Templates » Forms for datalists - two input fields with password - how to check?

Forms for datalists - two input fields with password - how to check?

Lise T. Pedersen
Reply

I need to make a form, where two of the fields has to be "insert wanted password" and "repeat wanted password" - and of course I would like to check if these to inputs are the same.

Can someone give me an example of the javascript which I have to use for this kind of form validation?

/Lise


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Lise

I've found this example that is pretty good:

http://stackoverflow.com/questions/16990378/javascript-form-validation-with-password-confirming

Of course it needs to be modified to the form you have created. Are you using Forms 7 or the old forms?

Nicolai

 
Lise T. Pedersen
Reply

Hi Nicolai

Luckily i'm using Forms 7, needed to validate a checkbox too, and as you know, its not possible in the old module. I have several times used the validation script from http://blog.grublestova.no/Dynamicweb/Dynamicweb-modules/dynamicweb-forms-DW7.aspx

Would be nice if it can be used with this script - I'll have a look at it!

Thanks for a quick answer!

Lise

 
Lise T. Pedersen
Reply

But if anyone has a template/script, that validates for same content in to input (wanted password) fields - AND perhaps for if a checkbox is checked, and if it is already implementet in forms 7 validation, then I would really like to hear from you!!!!

Lise :-)

 
Nicolai Høeg Pedersen
Reply

Hi Lise

I've updated the validation.js to be able to check for check boxes and for mathcing password fields

Attached the js and a HTML file with samples.

 
Lise T. Pedersen
Reply

My hero of the day - and the entire week!!!! Thank you - I will test it immediately!

 
Lise T. Pedersen
Reply

Hi again, Nicolai!

The validation seemed to work fine, I only have the problem that I can't figure out how to insert the "samevalue" message about which field the second password has to be compared to. In your example you have it like this: samevalue(NameOfField) but if I try to write something like that in my template, the text in () 0is being ignored. And if I write it ind the settings for the textinput (samevalue(xx) in the forms module - then the validation method is not recognized.

Can you give me a hint for what to do to solve this? 

/LIse

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Lise

The samevalue had a problem with _ in system names, that have been fixed. Your form now validates as it should.

Attached an updated version of the script.

Nicolai

Votes for this answer: 1
 
Lise T. Pedersen
Reply

I am now using this validation for all my forms, but would like it to be even better - hope I can get some help for it.

If I check for integers, e.g. a zip-code or a phone number, I would like to be able to tell that the zip is four numbers, and the phone number is eight numbers. Is it possible to connect the validation field and the max lenght field in some way, so that the error message is like "The input must be numbers, max 8" (or something more elegant...) and of course, both is validated?

Or do I just have to use the "max lenght" validation instead?

/Lise

 
Nicolai Høeg Pedersen
Reply

Hi Lise

You can just combine the validations - add more validation inputs for each field - and give them a custom error message, something like this:

Zip:<input type="text" name="zip" /><br />
<input type="hidden" name="__validate" value="zip|integer|The zip code must be numbers and 4 characters long" />
<input type="hidden" name="__validate" value="zip|min(4)|The zip code must be numbers and 4 characters long" />
<input type="hidden" name="__validate" value="zip|max(4|The zip code must be numbers and 4 characters long)" />

 

You must be logged in to post in the forum