added validation on the update forms too

main
Grim0o5 6 months ago
parent 8bafb759d7
commit 222bb7c6ba
  1. 16
      employerprofile.php
  2. 96
      jobseekerprofile.php
  3. 20
      phonevalidation.js

@ -53,7 +53,7 @@ if ($result->num_rows > 0) {
<div class="card-body">
<h2 class="card-title text-2xl font-bold text-center mb-6">Employer Profile</h2>
<form method="POST" action="updateemployeeprofile.php" enctype="multipart/form-data" class="space-y-6">
<form method="POST" action="updateemployeeprofile.php" enctype="multipart/form-data" class="space-y-6" onsubmit="return validateForm();">
<!-- First Name -->
<div class="form-control">
<label class="label">
@ -109,18 +109,15 @@ if ($result->num_rows > 0) {
>
</div>
<!-- Phone Number -->
<!-- Phone -->
<div class="form-control">
<label class="label">
<span class="label-text">Phone Number</span>
</label>
<input
type="tel"
name="phone"
value="<?php echo isset($user['phone']) ? $user['phone'] : ''; ?>"
class="input input-bordered w-full"
required
>
<input type="text" name="phone" id="phone"
value="<?php echo isset($user['phone']) ? htmlspecialchars($user['phone']) : ''; ?>"
class="input input-bordered w-full" required>
<small id="contact-error" class="text-error"></small>
</div>
<!-- Company Address -->
@ -147,5 +144,6 @@ if ($result->num_rows > 0) {
</div>
<?php include 'footer.php'?>
<script src="phonevalidation.js"></script>
</body>
</html>

@ -35,14 +35,15 @@ $result = $stmt->get_result();
// Check if the user data was found
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
} else {
$user = []; // Set $user to an empty array to avoid errors
}
?>
<!DOCTYPE html>
<html lang="en" data-theme="light">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -50,6 +51,7 @@ if ($result->num_rows > 0) {
<link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/daisyui/2.6.0/full.css" rel="stylesheet">
</head>
<body class="min-h-screen bg-base-200 flex flex-col">
<?php include 'navbar.php' ?>
@ -57,20 +59,16 @@ if ($result->num_rows > 0) {
<div class="card max-w-2xl mx-auto bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title text-2xl font-bold text-center mb-6">Jobseeker Profile</h2>
<form method="POST" action="updateprofile.php" enctype="multipart/form-data" class="space-y-6">
<form method="POST" action="updateprofile.php" enctype="multipart/form-data" class="space-y-6" onsubmit="return validateForm();" >
<!-- First Name -->
<div class="form-control">
<label class="label">
<span class="label-text">First Name</span>
</label>
<input
type="text"
name="first_name"
value="<?php echo isset($user['firstname']) ? htmlspecialchars($user['firstname']) : ''; ?>"
class="input input-bordered w-full"
required
>
<input type="text" name="first_name"
value="<?php echo isset($user['firstname']) ? htmlspecialchars($user['firstname']) : ''; ?>"
class="input input-bordered w-full" required>
</div>
<!-- Last Name -->
@ -78,13 +76,9 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">Last Name</span>
</label>
<input
type="text"
name="last_name"
value="<?php echo isset($user['lastname']) ? htmlspecialchars($user['lastname']) : ''; ?>"
class="input input-bordered w-full"
required
>
<input type="text" name="last_name"
value="<?php echo isset($user['lastname']) ? htmlspecialchars($user['lastname']) : ''; ?>"
class="input input-bordered w-full" required>
</div>
<!-- Email -->
@ -92,13 +86,9 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">Email</span>
</label>
<input
type="email"
name="email"
value="<?php echo isset($user['email']) ? htmlspecialchars($user['email']) : ''; ?>"
class="input input-bordered w-full"
required
>
<input type="email" name="email"
value="<?php echo isset($user['email']) ? htmlspecialchars($user['email']) : ''; ?>"
class="input input-bordered w-full" required>
</div>
<!-- username -->
@ -106,13 +96,9 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">username</span>
</label>
<input
type="text"
name="username"
value="<?php echo isset($user['username']) ? htmlspecialchars($user['username']) : ''; ?>"
class="input input-bordered w-full"
required
>
<input type="text" name="username"
value="<?php echo isset($user['username']) ? htmlspecialchars($user['username']) : ''; ?>"
class="input input-bordered w-full" required>
</div>
<!-- Phone -->
@ -120,13 +106,10 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">Phone Number</span>
</label>
<input
type="number"
name="phone"
value="<?php echo isset($user['phone']) ? htmlspecialchars($user['phone']) : ''; ?>"
class="input input-bordered w-full"
required
>
<input type="text" name="phone" id="phone"
value="<?php echo isset($user['phone']) ? htmlspecialchars($user['phone']) : ''; ?>"
class="input input-bordered w-full" required>
<small id="contact-error" class="text-error"></small>
</div>
<!-- Location -->
@ -134,13 +117,9 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">Location</span>
</label>
<input
type="text"
name="location"
value="<?php echo isset($user['location']) ? htmlspecialchars($user['location']) : ''; ?>"
class="input input-bordered w-full"
required
>
<input type="text" name="location"
value="<?php echo isset($user['location']) ? htmlspecialchars($user['location']) : ''; ?>"
class="input input-bordered w-full" required>
</div>
<!-- Skills -->
@ -148,11 +127,8 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">Skills</span>
</label>
<textarea
name="skills"
class="textarea textarea-bordered h-24"
required
><?php echo isset($user['skills']) ? htmlspecialchars($user['skills']) : ''; ?></textarea>
<textarea name="skills" class="textarea textarea-bordered h-24"
required><?php echo isset($user['skills']) ? htmlspecialchars($user['skills']) : ''; ?></textarea>
</div>
<!-- Experience -->
@ -160,11 +136,8 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">Experience</span>
</label>
<textarea
name="experience"
class="textarea textarea-bordered h-24"
required
><?php echo isset($user['experience']) ? htmlspecialchars($user['experience']) : ''; ?></textarea>
<textarea name="experience" class="textarea textarea-bordered h-24"
required><?php echo isset($user['experience']) ? htmlspecialchars($user['experience']) : ''; ?></textarea>
</div>
<!-- Education -->
@ -172,11 +145,8 @@ if ($result->num_rows > 0) {
<label class="label">
<span class="label-text">Education</span>
</label>
<textarea
name="education"
class="textarea textarea-bordered h-24"
required
><?php echo isset($user['education']) ? htmlspecialchars($user['education']) : ''; ?></textarea>
<textarea name="education" class="textarea textarea-bordered h-24"
required><?php echo isset($user['education']) ? htmlspecialchars($user['education']) : ''; ?></textarea>
</div>
<!-- Submit Button -->
@ -189,5 +159,9 @@ if ($result->num_rows > 0) {
</div>
<?php include 'footer.php' ?>
<script src="phonevalidation.js"></script>
</body>
</html>

@ -0,0 +1,20 @@
function validateForm() {
const phoneInput = document.getElementById('phone');
const contactError = document.getElementById('contact-error');
let isValid = true;
// Clear any previous error messages
contactError.textContent = "";
// Validate Phone Number
const phoneCriteria = /^\d{10}$/; // Ensure exactly 10 digits
if (!phoneCriteria.test(phoneInput.value)) {
contactError.textContent = "Phone number must be exactly 10 digits.";
phoneInput.classList.add("border-red-500"); // Add red border if invalid
isValid = false;
} else {
phoneInput.classList.remove("border-red-500"); // Remove red border if valid
}
return isValid; // Return false to prevent submission if validation fails
}
Loading…
Cancel
Save