Advertisement
Lauda

Untitled

May 12th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.89 KB | None | 0 0
  1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  2. <%@page pageEncoding="UTF-8" %>
  3. <jsp:include page="header.jsp"/>
  4. <div class="content">
  5.   <div class="container">
  6.     <div class="row">
  7. <script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
  8. <script type="text/javascript">
  9. $(document).ready(function() {
  10.    
  11.     $("#register-form").validate({
  12.    
  13.         // RuleZ:
  14.         rules: {
  15.             username: {
  16.                 required: true,
  17.                 minlength: 3
  18.             },
  19.             password: {
  20.                 required: true,
  21.                 minlength: 6
  22.             },
  23.             confirm_password: {
  24.                 required: true,
  25.                 minlength: 6,
  26.                 equalTo: "#password"
  27.             },
  28.             name: "required",
  29.             lastName: "required",
  30.             email: {
  31.                 required: true,
  32.                 email: true
  33.             },
  34.             phone: {
  35.                 required: true,
  36.                 number: true
  37.             },
  38.             cbTos: "required"
  39.         },
  40.        
  41.         // Validation msg:
  42.         messages: {
  43.             firstname: "Please enter your first name",
  44.             lastname: "Please enter your last name",
  45.             password: {
  46.                 required: "Please provide a password",
  47.                 minlength: "Your password must be at least 6 characters long"
  48.             },
  49.             confirm_password: {
  50.                 required: "Please provide a password",
  51.                 minlength: "Your password must be at least 6 characters long",
  52.                 equalTo: "Please enter the same password as above"
  53.             },
  54.             email: "Please enter a valid email address",
  55.             phone: "Please enter a valid phone number",
  56.             cbTos: "Please accept our Terms and Conditions"
  57.         },
  58.        
  59.         // Using submitHandler to preform ajax calls only when form is validated!
  60.         submitHandler: function(form) {
  61.             var objectArray = $("#register-form :input").serializeArray(); // Make an array of input vals
  62.             var data, objectData = {};
  63.             action = 'new', name = null;
  64.            
  65.             for (var i in objectArray)
  66.             {
  67.                 name = objectArray[i].value;
  68.                 objectData[objectArray[i].name] = objectArray[i].value;
  69.             };
  70.  
  71.             // Delete stuff that's not needed for processing
  72.             delete objectData.confirm_password;
  73.             delete objectData.cbTos;
  74.  
  75.             data = { 'action' : action, 'data' : objectData };
  76.             data =  JSON.stringify(data);
  77.             data = "reg=" + data;
  78.                          
  79.             $.ajax({
  80.                 type: "POST",
  81.                 url: "<%=request.getContextPath()%>/RegisterServlet",
  82.                 data: data,
  83.                 dataType: "json"
  84.               }).
  85.                 success(function(res){
  86.                     if(res.url != null)
  87.                     {
  88.                         $("#msgBox").modal('show');  
  89.                         $("#msg").html(res.message);
  90.                         setTimeout(function() {
  91.                               window.location.href = res.url;
  92.                             }, 5000); // is k, 5sec
  93.                     }
  94.                    
  95.                     if (res.error) {
  96.                         $("#err").html(res.message);
  97.                         if ($("#err").is(":hidden"))
  98.                             $("#err").toggle();
  99.                        
  100.                     }
  101.  
  102.                 }).
  103.                 error(function(res) {
  104.                     if (res.error)
  105.                         {
  106.                             $("#err").text(res.message);
  107.                             $("#err").toggle();
  108.                         }
  109.                 });
  110.             return false;
  111.         }
  112.     });
  113.  
  114.     // Let's propose a username for our user when onFocus() event happens...
  115.     setTimeout(function() {
  116.     $("#username").focus(function()
  117.     {
  118.         console.log("got focus!");
  119.         var firstname = $("#firstName").val().toLowerCase();
  120.         var lastname = $("#lastName").val().toLowerCase();
  121.         console.log("firstname: " + firstname + " lastname: " + lastname);
  122.        
  123.         if (firstname && lastname && !this.value)
  124.         {
  125.             this.value = firstname + "." + lastname;
  126.         }
  127.     });
  128.     }, 0);
  129. });
  130.   </script>
  131. <!-- Register form -->
  132.                 <div class="col-md-6">
  133.                   <div class="formy well">
  134.                      <h4 class="title">Register a new account</h4>
  135.                                   <div class="form">
  136.                                     <div id="err" class="alert alert-danger" hidden="true"></div>
  137.                                    
  138.                                     <form id="register-form" method="post" class="form-horizontal">                                                                    
  139.                                            
  140.                                            <div class="form-group">
  141.                                             <label class="control-label col-md-3" for="name">Name</label>
  142.                                             <div class="col-md-6">
  143.                                               <input type="text" class="form-control" id="firstName" name="name" />
  144.                                             </div>
  145.                                           </div>
  146.                                          
  147.                                           <div class="form-group">
  148.                                             <label class="control-label col-md-3" for="lastname">Last name</label>
  149.                                             <div class="col-md-6">
  150.                                               <input type="text" class="form-control" id="lastName" name="lastName" />
  151.                                             </div>
  152.                                           </div>
  153.    
  154.                                              <div class="form-group">
  155.                                             <label class="control-label col-md-3" for="username2">Username</label>
  156.                                             <div class="col-md-6">
  157.                                               <input type="text" class="form-control" id="username" name="username" />
  158.                                             </div>
  159.                                           </div>
  160.                                           <!-- Password -->
  161.                                           <div class="form-group">
  162.                                             <label class="control-label col-md-3" for="password2">Password</label>
  163.                                             <div class="controls col-md-6">
  164.                                               <input type="password" class="form-control" id="password" name="password" />
  165.                                             </div>
  166.                                           </div>
  167.                                          
  168.                                             <div class="form-group">
  169.                                             <label class="control-label col-md-3" for="password2">Confirm Password</label>
  170.                                             <div class="controls col-md-6">
  171.                                               <input type="password" class="form-control" id="confirm_password" name="confirm_password" />
  172.                                             </div>
  173.                                           </div>
  174.                                                                        
  175.                                           <div class="form-group">
  176.                                             <label class="control-label col-md-3" for="phone">Phone</label>
  177.                                             <div class="col-md-6">
  178.                                               <input type="text" class="form-control" id="phone" name="phone" />
  179.                                             </div>
  180.                                           </div>
  181.                                          
  182.                                           <div class="form-group">
  183.                                             <label class="control-label col-md-3" for="username2">E-mail</label>
  184.                                             <div class="col-md-6">
  185.                                               <input type="text" class="form-control" id="email" name="email" />
  186.                                             </div>
  187.                                           </div>
  188.  
  189.                                           <div class="form-group">
  190.                                           <div class="col-md-9 col-md-offset-3">
  191.                                              <div class="checkbox inline">
  192.                                                 <label>
  193.                                                    <input type="checkbox" id="cbTos" name="cbTos" value="agree"> Agree with our Terms and Conditions
  194.                                                 </label>
  195.                                              </div>
  196.                                             </div>
  197.                                           </div>
  198.  
  199.                                           <!-- Buttons -->
  200.                                           <div class="form-group">
  201.                                              <!-- Buttons -->
  202.                                              <div class="col-md-6 col-md-offset-3">
  203.                                                 <button type="submit" id="reg_btn1" class="btn btn-default">Register</button>
  204.                                                 <button type="reset" class="btn btn-default">Reset</button>
  205.                                              </div>
  206.                                           </div>
  207.                                       </form>
  208.                                       <hr />
  209.                                       <h5>Hint</h5>
  210.                                            Register so you can fully explore our website.
  211.                                     </div>
  212.                                   </div>
  213.  
  214.                 </div>
  215.        </div>
  216.   </div>
  217. </div>
  218. <div id="msgBox" class="modal fade">
  219. <div class="modal-dialog">
  220.         <div class="modal-content">
  221.   <div class="modal-header">
  222.     <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  223.     <h4>Message:</h4>
  224.   </div>
  225.   <div class="modal-body">
  226.  
  227.     <div id="msg" class="form"></div>
  228.   </div>
  229.   <div class="modal-footer">
  230.     <p id="cntRedirect"><a href="<%=request.getContextPath()%>/">Home</a></p>
  231.     Note: Page will redirect automatically in 5 seconds.
  232.   </div>
  233.   </div>
  234.   </div>
  235. </div>
  236.  
  237. <jsp:include page="footer.jsp"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement