3 To validate passwords via javascript/xmlhttp:
5 <INPUT ID="password_field" TYPE="text">
6 <DIV ID="password_field_result">
7 <& '/elements/validate_password.html',
8 fieldid => 'password_field',
10 pkgnum => $pkgnum, # used if the service doesn't exist yet
13 The ID of the input field can be anything; the ID of the DIV in which to display results
14 should be the input id plus '_result'.
18 <& '/elements/xmlhttp.html',
19 'url' => $p.'misc/xmlhttp-validate_password.html',
20 'subs' => [ 'validate_password' ],
21 'method' => 'POST', # important not to put passwords in url
24 function add_password_validation (fieldid, submitid) {
25 var inputfield = document.getElementById(fieldid);
26 inputfield.onkeydown = function(e) {
28 if (window.event) { key = window.event.keyCode; }
29 else { key = e.which; } // for ff browsers
30 // some browsers allow the enter key to submit a form even if the submit button is disabled
31 // below prevents enter key from submiting form if password has not been validated.
33 var check = checkPasswordValidation();
37 inputfield.onkeyup = function () {
38 var fieldid = this.id+'_result';
39 var resultfield = document.getElementById(fieldid);
41 resultfield.innerHTML = '<SPAN STYLE="color: blue;">Validating password...</SPAN>';
42 validate_password('fieldid',fieldid,'svcnum','<% $opt{'svcnum'} %>','pkgnum','<% $opt{'pkgnum'} %>','contactnum','<% $opt{'contactnum'} %>','password',this.value,
44 result = JSON.parse(result);
45 var resultfield = document.getElementById(result.fieldid);
47 var errorimg = '<IMG SRC="<% $p %>images/error.png" style="width: 1em; display: inline-block; padding-right: .5em">';
48 var validimg = '<IMG SRC="<% $p %>images/tick.png" style="width: 1em; display: inline-block; padding-right: .5em">';
50 resultfield.innerHTML = validimg+'<SPAN STYLE="color: green;">Password valid!</SPAN>';
51 if (submitid){ document.getElementById(submitid).disabled = false; }
52 } else if (result.error) {
53 resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.error+'</SPAN>';
54 if (submitid){ document.getElementById(submitid).disabled = true; }
56 result.syserror = result.syserror || 'Server error';
57 resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.syserror+'</SPAN>';
58 if (submitid){ document.getElementById(submitid).disabled = true; }
64 resultfield.innerHTML = '';
69 add_password_validation('<% $opt{'fieldid'} %>', '<% $opt{'submitid'} %>');