[LON-CAPA-cvs] cvs: loncom /interface createaccount.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 08 Jul 2008 17:47:58 -0000


raeburn		Tue Jul  8 13:47:58 2008 EDT

  Modified files:              
    /loncom/interface	createaccount.pm 
  Log:
  - client side javascript validation of e-mail address format for e-mail being proposed as username.
  
  
Index: loncom/interface/createaccount.pm
diff -u loncom/interface/createaccount.pm:1.11 loncom/interface/createaccount.pm:1.12
--- loncom/interface/createaccount.pm:1.11	Tue Jul  8 09:57:00 2008
+++ loncom/interface/createaccount.pm	Tue Jul  8 13:47:57 2008
@@ -3,7 +3,7 @@
 # institutional log-in ID (institutional authentication required - localauth
 #  or kerberos) or an e-mail address.
 #
-# $Id: createaccount.pm,v 1.11 2008/07/08 13:57:00 raeburn Exp $
+# $Id: createaccount.pm,v 1.12 2008/07/08 17:47:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@
 use Apache::lonacc;
 use Apache::lonnet;
 use Apache::loncommon;
+use Apache::lonhtmlcommon;
 use Apache::lonlocal;
 use Apache::lonauth;
 use Apache::resetpw;
@@ -195,6 +196,9 @@
             $r->print(<$jsh>);
             $r->print(&javascript_setforms($now));
         }
+        if (grep(/^email$/,@cancreate)) {
+            $r->print(&javascript_validmail());
+        }
         $output = &print_username_form($domain,$domdesc,\@cancreate,$now,$lonhost,
                                        $courseid); 
     }
@@ -277,6 +281,27 @@
     return $js;
 }
 
+sub javascript_validmail {
+    my %lt = &Apache::lonlocal::texthash (
+               email => 'The e-mail address you entered',
+               notv  => 'is not a valid e-mail address',
+    );
+    my $output =  "\n".'<script type="text/javascript">'."\n".
+                  &Apache::lonhtmlcommon::javascript_valid_email()."\n";
+    $output .= <<"ENDSCRIPT";
+function validate_email() {
+    field = document.createaccount.useremail;
+    if (validmail(field) == false) {
+        alert("$lt{'email'}: "+field.value+" $lt{'notv'}.");
+        return false;
+    }
+    return true;
+}
+ENDSCRIPT
+    $output .= "\n".'</script>'."\n";
+    return $output;
+}
+
 sub print_username_form {
     my ($domain,$domdesc,$cancreate,$now,$lonhost,$courseid) = @_;
     my %lt = &Apache::lonlocal::texthash(
@@ -327,7 +352,7 @@
             my $emailform = '<input type="text" name="useremail" size="25" value="" />';
             my $captchaform = &create_captcha();
             my $submit_text = &mt('Request LON-CAPA account');
-            $output .=  '<form name="createaccount" method="post" onsubmit="validate_email();" action="/adm/createaccount">'.
+            $output .=  '<form name="createaccount" method="post" onSubmit="return validate_email()" action="/adm/createaccount">'.
                         &Apache::lonhtmlcommon::start_pick_box()."\n".
                         &Apache::lonhtmlcommon::row_title(&mt('E-mail address'),
                                                          'LC_pick_box_title')."\n".