diff --git a/src/css/styles.css b/src/css/styles.css index 8fec2de4ceef616b8d62dfadc3235ad6880a1b53..65a39fbca0436cadc6a4002837531781c9109434 100644 --- a/src/css/styles.css +++ b/src/css/styles.css @@ -88,7 +88,7 @@ label { clear: left; width: 150px; text-align: left; - + height: 25px; } .btn-register { /*width: 100%;*/ @@ -111,7 +111,8 @@ label { padding: 5px; /* Some padding */ border: 1px solid #ccc; /* Gray border */ box-sizing: border-box; /* Make sure that padding and width stays in place */ - margin-top: 10px; /* Add a top margin */ + margin-top: 5px; /* Add a top margin */ + margin-bottom: 5px; resize: vertical /* Allow the user to vertically resize the textarea (not horizontally) */ } @@ -176,3 +177,10 @@ input.form-control.validation { width: 15px; height: 15px; } + +.valid-status img { + width: 16px; + float: initial; + margin-bottom: -4px; + margin-left: 5px; +} diff --git a/src/js/register.js b/src/js/register.js index dd2dc8f20b460d36b7ada6df41c7989746996aa6..c514b9f21fedc71280cf14455c129eefab72aab4 100644 --- a/src/js/register.js +++ b/src/js/register.js @@ -2,15 +2,35 @@ function validate(field, str){ if (str.length != 0){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) { - if (this.responseText == 'valid'){ - document.getElementByClassName('valid-status')[0].innerHTML = '<img src="img/check.png" alt="valid">'; + if (this.readyState == 4 && this.status == 200) { + if (this.responseText == 'valid'){ + console.log(this.responseText); + if (field == 'username') { + document.getElementsByClassName('valid-status')[0].innerHTML = '<img src="img/check.png" alt="valid">'; } else { - document.getElementByClassName('valid-status')[0].innerHTML = '<img src="img/cross.png" alt="invalid">'; + document.getElementsByClassName('valid-status')[1].innerHTML = '<img src="img/check.png" alt="valid">'; + } + } else { + console.log(this.responseText); + if (field == 'username') { + document.getElementsByClassName('valid-status')[0].innerHTML = '<img src="img/cross.png" alt="invalid">'; + } else { + document.getElementsByClassName('valid-status')[1].innerHTML = '<img src="img/cross.png" alt="invalid">'; } } + } }; xmlhttp.open("GET", "validate.php?form=" + field + "&value=" + str, true); xmlhttp.send(); } } + +function checkConfirmPasswd(cpassform){ + if (cpassform.value != document.getElementsByTagName('input')[3].value){ + cpassform.style.border = '2px solid red'; + return false; + } else { + cpassform.style.border = ''; + return true; + } +} diff --git a/src/login.php b/src/login.php index 0264c609f86978ad5c575f0f162ad9cf1e5ab79b..16085a3b626734c1c5eaa2ef1cce80069ceb9cd0 100644 --- a/src/login.php +++ b/src/login.php @@ -24,7 +24,7 @@ <input type="password" class="form-control" name="password" ><br><br> <button type="submit" >GO!</button> </form> - <a class="signup-link" href="#">Don't have an account?</a> + <a class="signup-link" href="register.php">Don't have an account?</a> <br><br> </div> </div> diff --git a/src/register.php b/src/register.php index 1b28d11b1c468f2a89838ad6ab4c2693d36821f8..6663b8d8ebfccc9822913e96b8d605bead5186c8 100644 --- a/src/register.php +++ b/src/register.php @@ -4,6 +4,7 @@ <meta charset="utf-8"> <title>Sign Up</title> <link rel="stylesheet" href="css/styles.css"> + <script src="js/register.js" charset="utf-8"></script> </head> <body> <nav> @@ -21,13 +22,13 @@ <label>Your Name</label> <input type="text" class="form-control" name="nama" > <label>Username</label> - <input type="text" class="form-control validation" name="username" ><span class="valid-status"></span> + <input type="text" class="form-control validation" onkeyup="validate(this.name,this.value)" name="username" ><span class="valid-status"></span> <label>Email</label> - <input type="text" class="form-control validation" name="email" ><span class="valid-status"></span> + <input type="text" class="form-control validation" onkeyup="validate(this.name,this.value)" name="email" ><span class="valid-status"></span> <label>Password</label> <input type="password" class="form-control" name="password" > <label>Confirm Password</label> - <input type="password" class="form-control" name="cpassword" > + <input type="password" class="form-control" onkeyup="checkConfirmPasswd(this)" name="cpassword" > <label>Phone Number</label> <input type="text" class="form-control" name="phone" ><br><br> <div class="checkbox"> @@ -35,7 +36,7 @@ </div> <button type="submit" class="btn-register">REGISTER</button> </form> - <a class="signin-link" href="#">Already Have an account?</a> + <a class="signin-link" href="login.php">Already Have an account?</a> <br><br> </div> </div> diff --git a/src/validate.php b/src/validate.php index 0991ba24b482ded3d430dcaf555fbf10be83def7..49251773db9850ed392b0585f8b18bdcc4ccbf6a 100644 --- a/src/validate.php +++ b/src/validate.php @@ -19,9 +19,10 @@ function validateUsername($username) { // username exist if(mysqli_stmt_num_rows($stmt) == 1) { mysqli_stmt_bind_result($stmt, $hasil_id); - /* Hasil match buat session */ - return $hasil_id; - + if(mysqli_stmt_fetch($stmt)){ + /* Hasil match buat session */ + return $hasil_id; + } } } return 0; @@ -46,29 +47,31 @@ function validateEmail($email) { // username exist if(mysqli_stmt_num_rows($stmt) == 1) { mysqli_stmt_bind_result($stmt, $hasil_id); - /* Hasil match buat session */ - return $hasil_id; - + if(mysqli_stmt_fetch($stmt)){ + /* Hasil match buat session */ + return $hasil_id; + } } } return 0; } - -switch ($_GET['field']) { +$response = ''; +switch ($_GET['form']) { case 'username': - if (validateUsername($_GET['value']){ - echo 'valid'; - } else { + if (validateUsername($_GET['value'])){ echo 'invalid'; + } else { + echo 'valid'; } break; case 'email': - if (validateEmail($_GET['value']){ - echo 'valid'; - } else { + if (validateEmail($_GET['value'])){ echo 'invalid'; + } else { + echo 'valid'; } break; } +// echo $response; ?>