Prac10
Prac10
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="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
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";
}
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
$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";
Output: