how to integrate html and php files??
form.php
<!DOCTYPE
html>
<html>
<body>
<form action="action_page.php" method="get">
<!-- A text type
input field -->
Name : <input type="text"
name="name"><br><br>
<!-- A password
type input field -->
Password : <input type="password"
name="password"><br><br>
<!-- A multiline text field -->
<textarea rows="4" cols="50" name="text">
Sample multiline text field, where you can enter unlimited number
of characters.
</textarea><br><br>
<!-- One set of radio buttons with fieldset and legend
-->
<fieldset>
<legend>Gender</legend>
<input type="radio" name="gender" value="male">
Male<br>
<input type="radio" name="gender" value="female">
Female<br>
<input type="radio" name="gender" value="other"> Other
</fieldset>
<br><br>
<!-- One set of
check boxes -->
<input type="checkbox" name="vehicle1" value="Bike"> I have a
bike<br>
<input type="checkbox" name="vehicle2" value="Car"> I have a
car<br>
<input type="checkbox" name="vehicle3" value="Boat"> I have a
boat<br>
<br>
<!--A pull-down menu -->
<select name="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
<option value="yamaha">Yamaha</option>
<option value="Honda">Honda</option>
</select>
<br><br>
<!-- A submit
button and reset button -->
<button type="submit"
value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
</body>
</html>
action_page.php
<?php
$validname="/^[a-zA-Z .]+$/"; //Name validation pattern
$validPassword = "/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/";
//Password validation pattern
if(!isset($_GET["name"]) ||
!preg_match($validname,$_GET["name"]))
{
echo "<b>Error! Enter valid Name , Name should contain
alphabates and space only</b>";
}
else if(!isset($_GET["password"]) ||
!preg_match($validPassword,$_GET["password"]))
{
echo "Password Must contain at least one number and
one uppercase and lowercase letter, and at least 8 or more
characters";
}
else if(!isset($_GET["text"]))
{
echo "Error ! Please enter text in given
textArea";
}
else if(!isset($_GET["gender"]))
{
echo "Error ! Please select your Gender.";
}
else if(!isset($_GET["vehicle1"]) &&
!isset($_GET["vehicle2"]) &&
!isset($GET["vehicle3"]))
{
echo "Error ! Please Choose Your Vehicle";
}
else if(!isset($_GET["cars"]))
{
echo "Error ! Please choose your Car.";
}
else
{
$name = $_GET["name"]; //name entered by User
$password = $_GET["password"]; //Password entered by user
$text = $_GET["text"]; //Text Entered by User
$gender = $_GET["gender"]; //Gender opted by user
//check if which was selected by user
if(isset($_GET["vehicle1"]))
$vehicle1 = $_GET["vehicle1"];
if(isset($_GET["vehicle2"]))
$vehicle2 = $_GET["vehicle2"];
if(isset($_GET["vehicle3"]))
$vehicle3 = $_GET["vehicle3"];
$cars = $_GET["cars"]; //Car selected by User
//print all information submitted by User
echo "<fieldset>" ;
echo "<legend>Information submitted by You
</legend>";
echo "</br>Name : ".$name;
echo "</br>Password : ".$password;
echo "</br>Text : ".$text;
echo "</br>Gender : ".$gender;
if(isset($_GET["vehicle1"]))
echo "</br>Vehicle 1: ".$vehicle1;
if(isset($_GET["vehicle2"]))
echo "</br>Vehicle 2 : ".$vehicle2;
if(isset($_GET["vehicle3"]))
echo "</br>Vehicle 3 :".$vehicle3;
echo "</br>Car :
".$cars;
echo "</fieldset>";
}
?>
Hello student, I've added all the necessary comments in the code. Feel free to ask any further details.
CODE SCREENSHOTS:
form.php





header.php

footer.php

SAMPLE OUTPUT:


CODE TO COPY:
form.php
<!DOCTYPE html>
<html>
<body>
<?php include 'header.php';?>
<?php
$validname="/^[a-zA-Z .]+$/"; //Name validation pattern
$validPassword = "/(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}/";
//Password validation pattern
if ($_SERVER["REQUEST_METHOD"] == "GET") { //Set initial values to
variables
$name = $password = $text = $gender = $vehicle1 =
$vehicle2 = $vehicle3 = $cars = "";
}
$isValid = false;//Set is user data valid
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//Set values to the variables that user had given so
that we pertain the field values after Submit button click
if (isset($_POST["name"]))
$name = $_POST["name"];
if (isset($_POST["password"]))
$password =
$_POST["password"];
if (isset($_POST["text"]))
$text = $_POST["text"];
if (isset($_POST["gender"]))
$gender = $_POST["gender"];
if (isset($_POST["vehicle1"]))
$vehicle1 =
$_POST["vehicle1"];
if (isset($_POST["vehicle2"]))
$vehicle2 =
$_POST["vehicle2"];
if (isset($_POST["vehicle3"]))
$vehicle3 =
$_POST["vehicle3"];
if (isset($_POST["cars"]))
$cars = $_POST["cars"];
//Form validations
if(!isset($_POST["name"]) ||
!preg_match($validname,$_POST["name"])){
echo "<b>Error! Enter valid
Name , Name should contain alphabates and space only</b>";
}
else if(!isset($_POST["password"]) ||
!preg_match($validPassword,$_POST["password"])){
echo "Password Must contain at
least one number and one uppercase and lowercase letter, and at
least 8 or more characters";
}
else if(!isset($_POST["text"])){
echo "Error ! Please enter text in
given textArea";
}
else if(!isset($_POST["gender"])){
echo "Error ! Please select your
Gender.";
}
else if(!isset($_POST["vehicle1"]) &&
!isset($_POST["vehicle2"]) &&
!isset($_POST["vehicle3"])){
echo "Error ! Please Choose Your
Vehicle";
}
else if(!isset($_POST["cars"])){
echo "Error ! Please choose your
Car.";
}
else
{
$isValid = true; //All fields are
perfectly set, now we can display the values set by user
$name = $_POST["name"]; //name
entered by User
$password = $_POST["password"];
//Password entered by user
$text = $_POST["text"]; //Text
Entered by User
$gender = $_POST["gender"];
//Gender opted by user
//check if which was selected by
user
if(isset($_POST["vehicle1"]))
$vehicle1 =
$_POST["vehicle1"];
if(isset($_POST["vehicle2"]))
$vehicle2 =
$_POST["vehicle2"];
if(isset($_POST["vehicle3"]))
$vehicle3 =
$_POST["vehicle3"];
$cars = $_POST["cars"]; //Car
selected by User
}
}
?>
<?php
//When user data is not valid stay on the form page
if(!$isValid){
?>
<form action="<?=$_SERVER["PHP_SELF"]?>"
method="post">
<!-- A text type input field -->
Name : <input type="text" name="name" value="<?php echo
$name;?>"><br><br>
<!-- A password type input field -->
Password : <input type="password" name="password"
value="<?php echo $password;?>"><br><br>
<!-- A multiline text field -->
<textarea rows="4" cols="50" name="text" value="<?php echo
$text;?>">
Sample multiline text field, where you can enter unlimited number
of characters.
</textarea><br><br>
<!-- One set of radio buttons with fieldset and legend
-->
<fieldset>
<legend>Gender</legend>
<input type="radio" name="gender" value="male" <?php if
(isset($gender) && $gender=="male") echo
"checked";?>> Male<br>
<input type="radio" name="gender" value="female" <?php if
(isset($gender) && $gender=="female") echo
"checked";?>> Female<br>
<input type="radio" name="gender" value="other" <?php if
(isset($gender) && $gender=="other") echo
"checked";?>> Other
</fieldset>
<br><br>
<!-- One set of check boxes -->
<input type="checkbox" name="vehicle1" value="Bike" <?php if
(isset($vehicle1) && $vehicle1=="Bike") echo
"checked";?>> I have a bike<br>
<input type="checkbox" name="vehicle2" value="Car" <?php if
(isset($vehicle2) && $vehicle2=="Car") echo
"checked";?>> I have a car<br>
<input type="checkbox" name="vehicle3" value="Boat" <?php if
(isset($vehicle3) && $vehicle3=="Boat") echo
"checked";?>> I have a boat<br>
<br>
<!--A pull-down menu -->
<select name="cars">
<option value="volvo" <?php if($cars==='volvo') echo
'selected="selected"';?>>Volvo</option>
<option value="saab" <?php if($cars==='saab') echo
'selected="selected"';?>>Saab</option>
<option value="fiat" <?php if($cars==='fiat') echo
'selected="selected"';?>>Fiat</option>
<option value="audi" <?php if($cars==='audi') echo
'selected="selected"';?>>Audi</option>
<option value="yamaha" <?php if($cars==='yamaha') echo
'selected="selected"';?>>Yamaha</option>
<option value="Honda" <?php if($cars==='Honda') echo
'selected="selected"';?>>Honda</option>
</select>
<br><br>
<!-- A submit button and reset button -->
<button type="submit"
value="Submit">Submit</button>
<button type="reset" value="Reset">Reset</button>
</form>
<?php
}else {
//print all information submitted by User
echo "<fieldset>" ;
echo "<legend>Information submitted by You
</legend>";
echo "</br>Name : ".$name;
echo "</br>Password : ".$password;
echo "</br>Text : ".$text;
echo "</br>Gender : ".$gender;
if(isset($_POST["vehicle1"]))
echo "</br>Vehicle 1: ".$vehicle1;
if(isset($_POST["vehicle2"]))
echo "</br>Vehicle 2 : ".$vehicle2;
if(isset($_POST["vehicle3"]))
echo "</br>Vehicle 3 :".$vehicle3;
echo "</br>Car : ".$cars;
echo "</fieldset>";
}
?>
<?php include 'footer.php';?>
</body>
</html>
header.php
<?php
echo "<h1>Chegg
Study</h1><hr>";
?>
footer.php
<?php
echo "</br></br><hr>© 2003-2019
Chegg Inc. All rights reserved.";
?>
how to integrate html and php files?? Integrate the HTML form and the handling PHP scripting...