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) {
25 var inputfield = document.getElementById(fieldid);
26 inputfield.onchange = function () {
27 var fieldid = this.id+'_result';
28 var resultfield = document.getElementById(fieldid);
30 resultfield.innerHTML = '<SPAN STYLE="color: blue;">Validating password...</SPAN>';
31 validate_password('fieldid',fieldid,
32 'svcnum',<% $opt{'svcnum'} |js_string %>,
33 'pkgnum',<% $opt{'pkgnum'} |js_string %>,
34 'password',this.value,
36 result = JSON.parse(result);
37 var resultfield = document.getElementById(result.fieldid);
39 var errorimg = '<IMG SRC="<% $p %>images/error.png" style="width: 1em; display: inline-block; padding-right: .5em">';
40 var validimg = '<IMG SRC="<% $p %>images/tick.png" style="width: 1em; display: inline-block; padding-right: .5em">';
42 resultfield.innerHTML = validimg+'<SPAN STYLE="color: green;">Password valid!</SPAN>';
43 } else if (result.error) {
44 resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.error+'</SPAN>';
46 result.syserror = result.syserror || 'Server error';
47 resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.syserror+'</SPAN>';
53 resultfield.innerHTML = '';
57 add_password_validation('<% $opt{'fieldid'} %>');