stray closing /TABLE in the no-ticket case
[freeside.git] / httemplate / elements / validate_password.html
1 <%doc>
2
3 To validate passwords via javascript/xmlhttp:
4
5   <INPUT ID="password_field" TYPE="text">
6   <DIV ID="password_field_result">
7   <& '/elements/validate_password.html', 
8      fieldid  => 'password_field',
9      svcnum   => $svcnum
10   &>
11
12 The ID of the input field can be anything;  the ID of the DIV in which to display results
13 should be the input id plus '_result'.
14
15 </%doc>
16
17 <& '/elements/xmlhttp.html',
18     'url'  => $p.'misc/xmlhttp-validate_password.html',
19     'subs' => [ 'validate_password' ],
20     'method' => 'POST', # important not to put passwords in url
21 &>
22 <SCRIPT>
23 function add_password_validation (fieldid) {
24   var inputfield = document.getElementById(fieldid);
25   inputfield.onchange = function () {
26     var fieldid = this.id+'_result';
27     var resultfield = document.getElementById(fieldid);
28     if (this.value) {
29       resultfield.innerHTML = '<SPAN STYLE="color: blue;">Validating password...</SPAN>';
30       validate_password('fieldid',fieldid,'svcnum','<% $opt{'svcnum'} %>','password',this.value,
31         function (result) {
32           result = JSON.parse(result);
33           var resultfield = document.getElementById(result.fieldid);
34           if (resultfield) {
35             var errorimg = '<IMG SRC="<% $p %>images/error.png" style="width: 1em; display: inline-block; padding-right: .5em">';
36             var validimg = '<IMG SRC="<% $p %>images/tick.png" style="width: 1em; display: inline-block; padding-right: .5em">';
37             if (result.valid) {
38               resultfield.innerHTML = validimg+'<SPAN STYLE="color: green;">Password valid!</SPAN>';
39             } else if (result.error) {
40               resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.error+'</SPAN>';
41             } else {
42               result.syserror = result.syserror || 'Server error';
43               resultfield.innerHTML = errorimg+'<SPAN STYLE="color: red;">'+result.syserror+'</SPAN>';
44             }
45           }
46         }
47       );
48     } else {
49       resultfield.innerHTML = '';
50     }
51   };
52 }
53 add_password_validation('<% $opt{'fieldid'} %>');
54 </SCRIPT>
55
56 <%init>
57 my %opt = @_;
58 </%init>
59
60