Advertisement
Guest User

kobi val form

a guest
Aug 10th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5.     <meta charset="utf-8" />
  6.     <title>בדיקת טופס</title>
  7.     <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  8.     <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-rtl/3.2.0-rc2/css/bootstrap-rtl.min.css" rel="stylesheet">
  9.    
  10.     <script type="text/javascript">
  11.         function CheckForm(form) {
  12.             var errors = []; // מערך שגיאות
  13.             var errorsDiv = document.getElementById('errors'); // בלוק שיחזיק את תוכן השגיאות
  14.             var username = form.username; // שם משתמש
  15.             var password = form.password; // סיסמא
  16.  
  17.             hide(errorsDiv); // העלמת הבלוק שמחזיק את השגיאות
  18.  
  19.             if (IsEmpty(username.value)) // אם שם המשתמש ריק
  20.                 errors.push('עליך להכניס שם משתמש!');
  21.             if (IsEmpty(password.value)) // אם סיסמה ריקה
  22.                 errors.push('עליך להכניס סיסמה!');
  23.  
  24.             // ניתן להוסיף גם בדיקות כגון האם שם המשתמש מכיל רק אותיות באנגלית וכדומה
  25.  
  26.             if (errors.length) { // האם יש שגיאות במערך
  27.                 show(errorsDiv); // הצגת בלוק השגיאות
  28.                 errorsDiv.innerHTML = errors.join('<br />'); // הצגת השגיאות בבלוק המתאים
  29.                 return false;
  30.             }
  31.  
  32.             // אם הגענו לכאן, כל הבדיקות עברו בהצלחה והטופס תקין. אפשר לעשות כרצונכם
  33.             return true;
  34.         }
  35.  
  36.         function show(x) { // הצגת אלמנט
  37.             x.style.display = 'block';
  38.         }
  39.  
  40.         function hide(x) { // העלמת אלמנט
  41.             x.style.display = 'none';
  42.         }
  43.  
  44.         function IsEmpty(s) { // הפונקציה מחזיקה האם s ריק
  45.             return s == null || s.trim() == "";
  46.         }
  47.     </script>
  48.  
  49.     <style>
  50.         * {
  51.             outline: 0 !important;
  52.         }
  53.         .kobi_form {
  54.             margin-top: 15px;
  55.         }
  56.  
  57.         #errors {
  58.             display: none;
  59.             width: 412px;
  60.             padding: 5px;
  61.             margin-top: 10px;
  62.         }
  63.     </style>
  64. </head>
  65. <body dir="rtl">
  66.     <div class="container">
  67.         <form class="form-inline kobi_form" method="post" name="kobiForm" role="form" onsubmit="return CheckForm(this)">
  68.             <div class="form-group">
  69.                 <label class="sr-only" for="username">שם משתמש:</label>
  70.                 <input type="text" class="form-control" name="username" id="username" placeholder="שם משתמש">
  71.             </div>
  72.             <div class="form-group">
  73.                 <label class="sr-only" for="pwd">סיסמה:</label>
  74.                 <input type="password" name="password" class="form-control" id="pwd" placeholder="סיסמה">
  75.             </div>
  76.             <button type="submit" class="btn btn-default">שלח</button>
  77.         </form>
  78.         <div id="errors" class="alert alert-warning"></div>
  79.     </div>
  80.  
  81.     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.js"></script>
  82.     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  83. </body>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement