Skip to content
Snippets Groups Projects
Commit c2ae002b authored by Girvandi Ilyas's avatar Girvandi Ilyas
Browse files

register validation and image upload complete, minor changes on register

parent a90abf24
1 merge request!42Projekers - 13515051 - Girvandi Ilyas
...@@ -25,18 +25,55 @@ if(!$_POST) { ...@@ -25,18 +25,55 @@ if(!$_POST) {
if(isset($_POST["submit"])) { if(isset($_POST["submit"])) {
$user = new User; $user = new User;
$userid = $_GET['id']; $userid = $_GET['id'];
$name = $_POST['name'];
$phone = $_POST['phone'];
$isDriver = 0; $isDriver = 0;
if(isset($_POST['driver'])) { $image = "";
if($_POST['driver'] == 'on') { $name = "";
$isDriver = 1; $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']))) if(isset($_POST['driver'])) {
$image = $_POST['image-file']; $isDriver = 1;
$user -> updateProfileById($userid,$name,$phone,$isDriver,$image); } else {
$isDriver = 0;
}
$user->updateProfileById($userid, $name, $phone, $isDriver, $image);
header('Location: ../view/edit-profile.php?id=' . $userid); header('Location: ../view/edit-profile.php?id=' . $userid);
} }
......
...@@ -33,7 +33,6 @@ function checkAllInput() { ...@@ -33,7 +33,6 @@ function checkAllInput() {
alert("Name must be 1-20 characters long!"); alert("Name must be 1-20 characters long!");
return false; return false;
} }
//Check Phone //Check Phone
var regex = /^08([0-9]){1,}$/; var regex = /^08([0-9]){1,}$/;
if(phone.value == "") { if(phone.value == "") {
......
...@@ -102,42 +102,4 @@ function checkAllInput() { ...@@ -102,42 +102,4 @@ function checkAllInput() {
alert("Phone number must be valid"); alert("Phone number must be valid");
return false; 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
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
</script> </script>
<script src="../js/edit-profile.js"></script> <script src="../js/edit-profile.js"></script>
</head> </head>
<body onload="getUserProfile();"> <body onload="getUserProfile();" onreset="getUserProfile()" onpageshow="getUserProfile()">
<div class="container"> <div class="container">
<h1>EDIT PROFILE INFORMATION</h1> <h1>EDIT PROFILE INFORMATION</h1>
<form action="../controller/edit-profile.php?id=<?php echo $_GET['id']?>" <form enctype="multipart/form-data" action="../controller/edit-profile.php?id=<?php echo $_GET['id']?>"
method="post" id="form" name="editForm" onsubmit="checkAllInput()"> method="post" id="form" name="editForm" onsubmit="return checkAllInput()">
<input type="hidden" id="userid" value="<?php echo $_GET['id'];?>"> <input type="hidden" id="userid" value="<?php echo $_GET['id'];?>">
<div class="edit-image"> <div class="edit-image">
<div class="div-profile-image"> <div class="div-profile-image">
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<label>Update profile picture</label> <label>Update profile picture</label>
<br /> <br />
<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> </div>
<div> <div>
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</div> </div>
<div> <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"> <input type="submit" value="SAVE" class="save" name="submit">
</div> </div>
</div> </div>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment