Lab #4
2. Create a form using a text box, check box, radio button, select, submit button. And display user inserted value in a new PHP page (e.g. student registration/inventory/library form).
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Buy Courses</title>
<style>
.form-input{
margin: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<form action="result.php" method="post">
<div class="form-input">
<input type="text" name="name" placeholder="Enter full name">
</div>
<div class="form-input">
<input type="number" name="age" min="10" max="164" placeholder="Enter age">
</div>
<div class="form-input">
<label for="courses">Select courses</label>
<select name="courses" id="courses">
<option value="java">Java</option>
<option value="python">Python</option>
<option value="c">C</option>
<option value="c++">C++</option>
<option value="javascript">JavaScript</option>
<option value="php">PHP</option>
</select>
</div>
<div class="form-input">
<input type="radio" name="gender" value="male" id="male">
<label for="male">Male</label>
<input type="radio" name="gender" value="female" id="female">
<label for="female">Female</label>
</div>
<div class="form-input">
<input type="checkbox" name="tac" id="tac">
<label for="tac">Accept <a href="#">terms and conditions</a></label>
</div>
<div class="form-input">
<button type="submit">Submit</button>
</div>
</form>
</div>
</body>
</html>
result.php
<?php
echo "Name: ".$_POST['name'].'<br/>';
echo "Age: ".$_POST['age'].'<br/>';
echo "Email: ".$_POST['email'].'<br/>';
echo "Course: ".$_POST['courses'].'<br/>';
echo "Gender: ".$_POST['gender'].'<br/>';
?>
Output
The output of first page (the simple registration form)
After clicking on Submit button
0 Comments
Post a Comment