0% found this document useful (0 votes)
7 views

Cs310 Assignment No. 02 Solution by VuCopier

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Cs310 Assignment No. 02 Solution by VuCopier

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

For Paid Assignment Solutions

WhatsApp now 03086278790


Solution by VuCopier

Cs310 Assignment No. 02


SEMESTER Fall 2024 VuCopier
VuCopier1.gmail.com For More Updates Visit
By VuCopier Vucopier.blogspot.com
0308-6278790

*** Contact for Paid Services ***


All Departments LMS Handling
All Subjects Assignments
All Subjects Quiz
All Subjects GDB

For More Updates


Join WhatsApp Group
https://chat.whatsapp.com/JwPEnqfqxhLB65qsO7ysoC

CODE
<?php

// Function to sanitize user input


function sanitizeInput($data) {
$data = trim($data); // Remove leading/trailing spaces
$data = stripslashes($data); // Remove backslashes
$data = htmlspecialchars($data); // Convert special characters to HTML entities
return $data;
}

// Initialize variables and error messages


$nameErr = $emailErr = $ratingErr = $commentErr = "";
$name = $email = $rating = $comment = "";
$isFormSubmitted = false;

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$isFormSubmitted = true;

// Name validation
if (empty($_POST["name"])) {

Visit
Vucopier.blogspot.com
For Paid Assignment Solutions
WhatsApp now 03086278790
Solution by VuCopier

$nameErr = "Name is required";


} else {
$name = sanitizeInput($_POST["name"]);
if (!preg_match("/^[a-zA-Z ]*$/", $name)) {
$nameErr = "Name must contain only letters and spaces";
}
}

// Email validation
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = sanitizeInput($_POST["email"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
}
}

// Event rating validation


if (empty($_POST["rating"])) {
$ratingErr = "Rating is required";
} else {
$rating = sanitizeInput($_POST["rating"]);
if (!is_numeric($rating) || $rating < 1 || $rating > 5) {
$ratingErr = "Rating must be a number between 1 and 5";
}
}

// Comment validation
if (empty($_POST["comment"])) {
$comment = ""; // Optional field
} else {
$comment = sanitizeInput($_POST["comment"]);
if (strlen($comment) > 250) {
$commentErr = "Comment cannot exceed 250 characters";
}
}
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Event Feedback Form</title>
<style>
.error { color: red; }
</style>
</head>
<body>

<?php
if ($isFormSubmitted && empty($nameErr) && empty($emailErr) && empty($ratingErr) &&
empty($commentErr)) {
echo "<h2>Confirmation</h2>";
echo "<p>Thank you for your feedback!</p>";
echo "<p>Name: " . $name . "</p>";

Visit
Vucopier.blogspot.com
For Paid Assignment Solutions
WhatsApp now 03086278790
Solution by VuCopier

echo "<p>Email: " . $email . "</p>";


echo "<p>Rating: " . $rating . "</p>";
echo "<p>Comment: " . $comment . "</p>";
} else {
?>

<h2>Event Feedback Form</h2>


<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="name">Name:</label>
<input type="text" name="name" id="name" value="<?php echo $name; ?>">
<span class="error">* <?php echo $nameErr; ?></span>
<br><br>
<label for="email">Email Address:</label>
<input type="email" name="email" id="email" value="<?php echo $email; ?>">
<span class="error">* <?php echo $emailErr; ?></span>
<br><br>
<label for="rating">Event Rating (1-5):</label>
<input type="number" name="rating" id="rating" min="1" max="5" value="<?php echo $rating; ?>">
<span class="error">* <?php echo $ratingErr; ?></span>
<br><br>
<label for="comment">Comments:</label>
<textarea name="comment" id="comment" rows="5" cols="30"><?php echo $comment; ?></textarea>
<span class="error"><?php echo $commentErr; ?></span>
<br><br>
<input type="submit" value="Submit">
</form>

<?php
}
?>

</body>
</html>

Visit
Vucopier.blogspot.com
For Paid Assignment Solutions
WhatsApp now 03086278790
Solution by VuCopier

*** Contact for Paid Services ***


All Departments LMS Handling
All Subjects Assignments
All Subjects Quiz
All Subjects GDB

For More Updates


Join WhatsApp Group
https://chat.whatsapp.com/JwPEnqfqxhLB65qsO7ysoC

VuCopier

Visit
Vucopier.blogspot.com

You might also like