<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$firstName = filter_input(INPUT_GET,'firstName');
$employeeID = filter_input(INPUT_GET,'employeeID');
$officeNum = filter_input(INPUT_GET, 'officeNum');
$compOS = filter_input(INPUT_GET, 'compOS');
$option = $_GET['option'];
function printForm(){
print <<<HERE
<form action = "" method = "get">
<label for = "firstName">What is your name?: </label>
<input type = "text" name = "firstName" id = "firstName">
<br \>
<label for = "employeeID">What is your employee ID?: </label>
<input type = "text" name = "employeeID" id = "employeeID">
<br \>
<label for = "officeNum">What is your office number?: </label>
<input type = "text" name = "officeNum" id = "officeNum">
<br \>
<label for = "compOS">What is your office computers OS?: </label>
<input type = "text" name = "compOS" id = "compOS">
<br \>
<input type = "submit" value = "Submit" id = "Submit" name = "Submit">
</form>
<br />
<br />
HERE;
if (isset($_GET['Submit'])) {
printer();
}
}
function printer(){
global $firstName;
global $employeeID;
global $officeNum;
global $compOS;
echo nl2br ("Hi $firstName, \n Your employee ID is $employeeID, your office is room $officeNum, and your OS is $compOS. \n If this is correct, click Yes. Otherwise, click No.");
print <<<HERE
<form action = "Q3FINALA.php" method = "get">
<input type = "radio" name = "option" value = "nay" checked> No <br>
<input type = "radio" name = "option" value = "yay"> Yes <br>
<input type = "submit" value = "Submit" id = "Submit" name = "Submit">
</form>
<br />
<br />
HERE;
}
printForm();
?>
</body>
</html>
Above is Q3FINAL.php
and below is Q3FINALA.php
<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$option = $_GET['option'];
function checker($option){
print $option;
if ($option == 'yay') {
echo "Thank you for verifying your information";
}
else {
printForm();
}
}
checker($option);
?>
</body>
</html>
So I was attempting to create a form that accepted some inputs and then returned those same inputs in a paragraph. This is done in the "printForm()" and "printer()" functions, and that part of the code works exactly as planned.
However, I was trying to look up reasons why the if statement in the "checker()" function doesn't appear to work. I threw a print statement into it to see if it was properly inheriting the $option value (it shows up in the 'print' properly- as well as in the browser). But, the if and else conditions just do not run in the new window.
Is there a problem with how I'm calling the function? Is there a rule with if statements that I'm unaware of?
I just want the checker function to work properly by either echoing the string, or bouncing back the first form depending on if 'yes' or 'no' are picked from teh radio buttons.
Aucun commentaire:
Enregistrer un commentaire