Skip to content

Commit

Permalink
Form validation for upload book functional
Browse files Browse the repository at this point in the history
  • Loading branch information
bdngeorge committed Dec 5, 2021
1 parent b0640fb commit 66c0d36
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
3 changes: 2 additions & 1 deletion account/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
die;
}
}
echo "your password or username is incorrect";
echo "<script>alert(your password or username is incorrect);<script>";
}
}

Expand All @@ -45,6 +45,7 @@
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous">
</script>
<script type="text/javascript" src="../scripts/form-validation.js"></script>

</head>
<body>
Expand Down
14 changes: 1 addition & 13 deletions catalog/uploadBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@

$imgExt = array('jpeg', 'jpg', 'png');


if (!in_array($fileExt, $imgExt) or !$fileError === 0 or $filesize >= 10000000){
echo "Error with file, please upload a different file. File must be of typpe jpep, jpg, or png. File size must be under 10MB. Your file size is ";
echo $filesize. ".";
}

$uploads_dir = "../resources/bookImg";
$imgIdentifier= $subj .'-'. rand(999999999, 9999999999).'.'.$fileExt;
move_uploaded_file($tmploc, $uploads_dir.'/'.$imgIdentifier);
Expand All @@ -50,13 +44,6 @@
$statement->bind_param("sssssssds", $imgIdentifier, $title, $authors, $isbn, $subj, $cond, $desc, $price, $userEmail);
$success = $statement->execute();
$statement->close();

if ($success) {
echo "Your file was successfully uploaded";
} else {
echo "Sorry " . $userEmail;
echo "There was an error on our server, please try again";
}
}

?>
Expand All @@ -74,6 +61,7 @@
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous">
</script>
<script type="text/javascript" src="../scripts/form-validation.js"></script>
</head>
<body>
<?php include("../includes/header.inc.php"); ?>
Expand Down
45 changes: 42 additions & 3 deletions scripts/form-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,51 @@ function validateSignUp(formObj) {
}
if(message != ""){
alert(message);
return false;

return false;
}
return true;
}

function validateUpload(formObj) {

var message = "";
if(formObj.title.value == "") {
message += "Please enter a title.\n";
}
if(formObj.authors.value == "") {
message += "Please enter an author or authors.\n";
}
if(formObj.desc.value == "") {
message += "Please enter a description.\n";
}
if(formObj.isbn.value == "") {
message += "Please enter an ISBN.\n";
} else {
let isbn = formObj.isbn.value;
for(let i = 0; i < isbn.length; i++) {
if(!(isbn[i] >= '0' && isbn[i] <= '9')) {
message += "ISBN must only contain digits 0-9.\n";
break;
}
}
}
if(formObj.price.value == "") {
message += "Please enter an price.\n";
} else {
let price = formObj.price.value;
for(let i = 0; i < price.length; i++) {
if(!price[i] == '.' && !(price[i] >= '0' && price[i] <= '9')) {
message += "Price must only contain digits 0-9.\n";
break;
}
}
}
if(formObj.file.value == "") {
message += "Please provide an image for the textbook.\n";
}

if(message != ""){
alert(message);
return false;
}
return true;
}

0 comments on commit 66c0d36

Please sign in to comment.