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

Prac10

The document contains a registration form and a validation exercise using HTML and PHP. It includes code for a registration form with various input fields, including textboxes, radio buttons, and checkboxes, along with PHP code to process the submitted data. Additionally, it presents another form for validation purposes, demonstrating similar input handling and output display.

Uploaded by

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

Prac10

The document contains a registration form and a validation exercise using HTML and PHP. It includes code for a registration form with various input fields, including textboxes, radio buttons, and checkboxes, along with PHP code to process the submitted data. Additionally, it presents another form for validation purposes, demonstrating similar input handling and output display.

Uploaded by

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

dd

NAME: SUMEDH SANJAY RAUT


CLASS: CO6I(A)
ROLL NO: 532
SUBJECT: WBP(22619)

PRACTICAL NO: 10
XI. Program Code:
1. Write a program to design a registration form using textbox,radio buttion,checkbox
and button.
Code:
<html>
<body>
<h1>*** Registration Form ***</h1>
<form method="POST" action="Login1.php">
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" required><br><br>

<label for="middlename">Middle Name:</label>


<input type="text" id="middlename" name="middlename"><br><br>

<label for="lastname">Last Name:</label>


<input type="text" id="lastname" name="lastname" required><br><br>

<label for="phone">Phone Number:</label>


<input type="tel" id="phone" name="phone" pattern="[0-9]{10}" required><br><br>

<label for="address">Address:</label>
<textarea id="address" name="address" required></textarea><br><br>

<label>Gender:</label>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female</label><br><br>

<label>Hobbies:</label>
<input type="checkbox" name="hobbies[]" value="Reading"> Reading
<input type="checkbox" name="hobbies[]" value="Traveling"> Traveling
<input type="checkbox" name="hobbies[]" value="Gaming"> Gaming<br><br>

<label for="subject">Subject:</label>
<input type="text" id="subject" name="subject" required><br><br>
dd

<button type="submit">Submit</button>
</form>
</body>
</html>

*PHP Code process.php


Code:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {

$firstname = htmlspecialchars($_POST['firstname']);
$middlename = htmlspecialchars($_POST['middlename']);
$lastname = htmlspecialchars($_POST['lastname']);
$phone = htmlspecialchars($_POST['phone']);
$address = htmlspecialchars($_POST['address']);
$gender = isset($_POST['gender']) ? $_POST['gender'] : "Not specified";
$subject = htmlspecialchars($_POST['subject']);

if (!empty($_POST['hobbies'])) {
$hobbies = implode(", ", $_POST['hobbies']);
} else {
$hobbies = "No hobbies selected";
}

echo "<h2>Registration Successful!</h2>";


echo "<p><strong>First Name:</strong> $firstname</p>";
echo "<p><strong>Middle Name:</strong> $middlename</p>";
echo "<p><strong>Last Name:</strong> $lastname</p>";
echo "<p><strong>Phone Number:</strong> $phone</p>";
echo "<p><strong>Address:</strong> $address</p>";
echo "<p><strong>Gender:</strong> $gender</p>";
echo "<p><strong>Hobbies:</strong> $hobbies</p>";
echo "<p><strong>Subject:</strong> $subject</p>";
} else {
echo "<h2>Error: Form not submitted properly!</h2>";
}
?>
dd

Output:
dd

XI. Exercise
1. Develop web page and do validation using control text box, radio button, check box
and button.
Code:
<html>
<head>
<title>Form Validation</title>
<body>
<h2>***Form Validation***</h2>
<form action="form.php" method="POST">
Name:<input type="text" name="name"><br><br>
Phone Number:<input type="number" name="phone"><br><br>
E-Mail:<input type="text" name="text"><br><br>
<label>Gender:</label>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male</label>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female</label><br><br>
<label>Select Your Hobbies:</label><br>
<input type="checkbox" name="hobbies[]" value="Reading"> Reading
<input type="checkbox" name="hobbies[]" value="Traveling"> Traveling
<input type="checkbox" name="hobbies[]" value="Gaming"> Gaming<br><br>
<label>Select Your Favorite Subjects:</label><br>
<Select name="subject[]" multiple>
<option value="MAD">MAD</option>
<option value="WBP">WBP</option>
<option value="ETI">ETI</option>
<option value="PWP">PWP</option>
</Select><br><br>
<input type="Submit">

</form>
</body>
</head>
</html>
dd

*PHP Code form.php


Code:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {

$name = htmlspecialchars($_POST["name"]);
$phone = htmlspecialchars($_POST["phone"]);
$email = htmlspecialchars($_POST["text"]);
$gender = isset($_POST["gender"]) ? htmlspecialchars($_POST["gender"]) : "Not Selected";
$hobbies = isset($_POST["hobbies"]) ? implode(", ", $_POST["hobbies"]) : "No Hobby Selected";
$subjects = isset($_POST["subject"]) ? implode(", ", $_POST["subject"]) : "No Subject Selected";

echo "<h2>Submitted Information</h2>";


echo "<p><strong>Name:</strong> $name</p>";
echo "<p><strong>Phone Number:</strong> $phone</p>";
echo "<p><strong>Email:</strong> $email</p>";
echo "<p><strong>Gender:</strong> $gender</p>";
echo "<p><strong>Hobbies:</strong> $hobbies</p>";
echo "<p><strong>Favorite Subjects:</strong> $subjects</p>";
} else {
echo "<h2>Invalid Request</h2>";
}
?>
dd

Output:

You might also like