Using PHP and HTML Create a form processor file named types.php that displays th
ID: 3597894 • Letter: U
Question
Using PHP and HTML Create a form processor file named types.php that displays the content of the HTML elements sent to it. Include a function called “value_input” to ensure text data received from the form is safe before displaying the data. Include an HTML element to navigate back to index.php.
a. action=”types.php”
b. method=”post”
c. Name textbox (required – display appropriate error message next to the control)
d. Favorite Cellphone textbox (required – display appropriate error message next to the control)
e. Favorite sport textbox (required – display appropriate error message next to the control)
f. Three radio buttons for favorite pets
g. Comments (optional)
h. Submit button
Explanation / Answer
index.html
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function check()
{
var x=document.getElementById("kname").value;
if(x=="")
{
document.getElementById("com").innerHTML="User name required";
return false;
}
var x=document.getElementById("fcep").value;
if(x=="")
{
document.getElementById("com").innerHTML="mobile number name required";
return false;
}
var x=document.getElementById("fsp").value;
if(x=="")
{
document.getElementById("com").innerHTML="sports name required";
return false;
}
var x=document.getElementById("pet");
if(x=="")
{
document.getElementById("com").innerHTML="sports name required";
return false;
}
}
</script>
<form name="myForm" action="types.php" method="post">
<label>username</label><input type="text" name ="kname" id="name"><br>
<label>mobile number</label> <input type="text" name="fcep" id="fcep"><br>
<label>Sport</label> <input type="text" name="fsp" id="fsp"><br>
<input type="radio" name="pet" id="pet" value="dog_a"> dog_a<br>
<input type="radio" id="pet" value="dog_b"> dog_b<br>
<input type="radio" id="pet" value="dog_c"> dog_c<br>
<input type="submit" value="Submit" >
<label id="com"></label>
</form>
</body>
</html>
types.php
<?php
$x=$_POST['kname'];
$y=$_POST['fcep'];
$z=$_POST['fsp'];
$p=$_POST['pet'];
function valid($a,$b,$c,$p){
if(isset($a) && isset($b) && isset($c) )
{
return 1;
}else
{
return 0;
}
}
$k=valid($x,$y,$z,$p);
if($k)
{
echo "username".$x.'<br>';
echo "mobile".$y.'<br>';
echo "sport".$z.'<br>';
echo "pet".$p;
}
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.