From c2ae002b0ea1e89875f3cea9e97fbf6eeddd1b39 Mon Sep 17 00:00:00 2001 From: girvandip <girvandip@gmail.com> Date: Fri, 6 Oct 2017 00:44:16 +0700 Subject: [PATCH] register validation and image upload complete, minor changes on register --- controller/edit-profile.php | 53 +++++++++++++++++++++++++++++++------ js/edit-profile.js | 1 - js/register.js | 38 -------------------------- view/edit-profile.php | 10 +++---- 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/controller/edit-profile.php b/controller/edit-profile.php index 357e3117..da8d0868 100644 --- a/controller/edit-profile.php +++ b/controller/edit-profile.php @@ -25,18 +25,55 @@ if(!$_POST) { if(isset($_POST["submit"])) { $user = new User; $userid = $_GET['id']; - $name = $_POST['name']; - $phone = $_POST['phone']; $isDriver = 0; - if(isset($_POST['driver'])) { - if($_POST['driver'] == 'on') { - $isDriver = 1; + $image = ""; + $name = ""; + $phone = ""; + $result = $user -> getUserById($userid); + while($row = mysqli_fetch_array($result)) { + $name = $row['name']; + $phone = $row['phone']; + $image = $row['image']; + $isDriver = $row['isDriver']; + } + if(isset($_POST['name'])) { + $name = $_POST['name']; + } + if(isset($_POST['phone'])) { + $phone = $_POST['phone']; + } + if(file_exists($_FILES["image-file"]["tmp_name"])) { + $targetDir = "../img/"; + $targetFile = $targetDir . basename($_FILES["image-file"]["name"]); + $uploadOK = 1; + $imageFileType = pathinfo($targetFile,PATHINFO_EXTENSION); + $check = getimagesize($_FILES["image-file"]["tmp_name"]); + if($check !== false) { + $uploadOK = 1; + } else { + $uploadOK = 0; + } + if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" + && $imageFileType != "gif" ) { + $uploadOk = 0; + } + if($uploadOK == 1) { + if (move_uploaded_file($_FILES["image-file"]["tmp_name"], $targetFile)) { + $image = basename($_FILES["image-file"]["name"]); + } + } + if($uploadOK == 0) { + echo 'no'; } } - //if(isset(($_POST['image']))) - $image = $_POST['image-file']; - $user -> updateProfileById($userid,$name,$phone,$isDriver,$image); + if(isset($_POST['driver'])) { + $isDriver = 1; + } else { + $isDriver = 0; + } + $user->updateProfileById($userid, $name, $phone, $isDriver, $image); header('Location: ../view/edit-profile.php?id=' . $userid); + } diff --git a/js/edit-profile.js b/js/edit-profile.js index d8b29eaf..ccd524e7 100644 --- a/js/edit-profile.js +++ b/js/edit-profile.js @@ -33,7 +33,6 @@ function checkAllInput() { alert("Name must be 1-20 characters long!"); return false; } - //Check Phone var regex = /^08([0-9]){1,}$/; if(phone.value == "") { diff --git a/js/register.js b/js/register.js index 71bfdc4e..1ee8fbe6 100644 --- a/js/register.js +++ b/js/register.js @@ -102,42 +102,4 @@ function checkAllInput() { alert("Phone number must be valid"); return false; } - - // var name = document.forms["form"]["full-name"].value; - // if(name == "") { - // alert("Your name field must be filled!"); - // return false; - // //Check username - // var username = document.forms["form"]["username"].value; - // if(username == "") { - // alert("Username field must be filled!"); - // return false; - // /// /Check email - // var email = document.forms["form"]["email"].value; - // if(email == "") { - // alert("Email field must be filled!"); - // return false; - // } -} - -function checkName() { - -} - -function checkPassword() { - //Check Password - var password = document.forms["form"]["password"].value; - var confirmPassword = document.forms["form"]["confirm-password"].value; - if(password == "") { - alert("Password field must be filled!"); - return false; - } else if(confirmPassword == "") { - alert("Confirm Password field must be filled!"); - return false; - } -} - -function checkPhone() { - //Check Phone - var phone = document.forms["form"]["phone"].value; } \ No newline at end of file diff --git a/view/edit-profile.php b/view/edit-profile.php index df7b8af1..ffc32ccc 100644 --- a/view/edit-profile.php +++ b/view/edit-profile.php @@ -8,11 +8,11 @@ </script> <script src="../js/edit-profile.js"></script> </head> -<body onload="getUserProfile();"> +<body onload="getUserProfile();" onreset="getUserProfile()" onpageshow="getUserProfile()"> <div class="container"> <h1>EDIT PROFILE INFORMATION</h1> - <form action="../controller/edit-profile.php?id=<?php echo $_GET['id']?>" - method="post" id="form" name="editForm" onsubmit="checkAllInput()"> + <form enctype="multipart/form-data" action="../controller/edit-profile.php?id=<?php echo $_GET['id']?>" + method="post" id="form" name="editForm" onsubmit="return checkAllInput()"> <input type="hidden" id="userid" value="<?php echo $_GET['id'];?>"> <div class="edit-image"> <div class="div-profile-image"> @@ -22,7 +22,7 @@ <label>Update profile picture</label> <br /> <br /> - <input type="file" name="image-file" value="browse.." id="image-file"> + <input type="file" name="image-file" value="browse.." id="image-file" onsubmit=""> </div> </div> <div> @@ -46,7 +46,7 @@ </div> <div> <div> - <a class="back" href="dashboard.php">BACK</a> + <a class="back" href="dashboard.php?id=<?php echo $_GET['id'];?>">BACK</a> <input type="submit" value="SAVE" class="save" name="submit"> </div> </div> -- GitLab