DATA VALIDATION
a) Registration form
Filename:Registration [Link]
<!DOCTYPE html>
<html>
<head>
<title>User Registration</title>
</head>
<body>
<h2>User Registration Form</h2>
<form method="post" action="process [Link]">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<br>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password"
required>
<br>
<input type="submit" value="Register">
</form>
</body>
</html>
Filename :process [Link]
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Collect form data
$username = htmlspecialchars($_POST["username"]);
$email = htmlspecialchars($_POST["email"]);
$password = htmlspecialchars($_POST["password"]);
$confirm_password = htmlspecialchars($_POST["confirm_password"]);
// Validate data
$errors = [];
if (empty($username)) {
$errors["username"] = "Username is required";
}
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors["email"] = "Invalid email address";
}
if (empty($password)) {
$errors["password"] = "Password is required";
}
if ($password !== $confirm_password) {
$errors["confirm_password"] = "Passwords do not match";
}
// If there are no errors, process the registration
if (empty($errors)) {
// Perform registration logic (save to database, etc.)
// For simplicity, let's just display a success message
echo "Registration successful!";
} else {
// Display errors and redirect back to the registration form
echo "Registration failed. Please fix the following errors:<br>";
foreach ($errors as $error) {
echo "- $error<br>";
}
echo '<a href="registration [Link]">Back to Registration Form</a>';
}
} else {
// Redirect to the registration form if accessed directly
header("Location: registration [Link]");
exit();
}
?>
b) Biodata form
filename :[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Biodata Form</title>
<style>
.error { color: red; }
</style>
</head>
<body>
<h2>Biodata Form</h2>
<form method="post" action="process_biodata.php">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br>
<label for="dob">Date of Birth:</label>
<input type="date" id="dob" name="dob" required>
<br>
<label for="gender">Gender:</label>
<select id="gender" name="gender" required>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
<br>
<label for="phone">Phone Number:</label>
<input type="tel" id="phone" name="phone" required>
<br>
<label for="address">Address:</label>
<textarea id="address" name="address" rows="4" required></textarea>
<br>
<label for="education">Education:</label>
<input type="text" id="education" name="education" required>
<br>
<label for="occupation">Occupation:</label>
<input type="text" id="occupation" name="occupation" required>
<br>
<label for="hobbies">Hobbies:</label>
<input type="text" id="hobbies" name="hobbies" required>
<br>
<label for="languages">Languages Known:</label>
<input type="text" id="languages" name="languages" required>
<br>
<label for="skills">Skills:</label>
<input type="text" id="skills" name="skills" required>
<br>
<label for="experience">Work Experience:</label>
<input type="text" id="experience" name="experience" required>
<br>
<label for="references">References:</label>
<input type="text" id="references" name="references" required>
<br>
<input type="submit" value="Submit">
</form>
<?php
// Display output message if available
if (isset($_GET['message'])) {
echo '<p class="output-message">' . htmlspecialchars($_GET['message']) .
'</p>';
}
?>
</body>
</html>
Filename: process_biodata.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Collect form data
$name = htmlspecialchars($_POST["name"]);
$email = htmlspecialchars($_POST["email"]);
$dob = htmlspecialchars($_POST["dob"]);
$gender = htmlspecialchars($_POST["gender"]);
$phone = htmlspecialchars($_POST["phone"]);
$address = htmlspecialchars($_POST["address"]);
$education = htmlspecialchars($_POST["education"]);
$occupation = htmlspecialchars($_POST["occupation"]);
$hobbies = htmlspecialchars($_POST["hobbies"]);
$languages = htmlspecialchars($_POST["languages"]);
$skills = htmlspecialchars($_POST["skills"]);
$experience = htmlspecialchars($_POST["experience"]);
$references = htmlspecialchars($_POST["references"]);
// Validate data
$errors = [];
// Add your own validation rules for each field
// For example, you might want to check the email format, phone number
format, etc.
if (empty($name)) {
$errors["name"] = "Name is required";
}
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors["email"] = "Invalid email address";
}
// Add validation for other fields as needed
// If there are no errors, you can process the biodata
if (empty($errors)) {
// Perform biodata processing logic (save to database, etc.)
// For simplicity, let's just display a success message
$message = "Biodata submitted successfully for $name.";
header("Location: [Link]?message=" . urlencode($message));
exit();
} else {
// Display errors and redirect back to the biodata form
echo "Biodata submission failed. Please fix the following errors:<br>";
foreach ($errors as $error) {
echo "- $error<br>";
}
echo '<a href="[Link]">Back to Biodata Form</a>';
}
} else {
// Redirect to the biodata form if accessed directly
header("Location:[Link]");
exit();
}
?>
OUTPUT: