PHP Интерактивность формы: любимый цвет на главной странице «выделяет» утверждение о любимом цвете на странице процессора - PullRequest
0 голосов
/ 22 апреля 2020

Я недавно начал работать с PHP в школе, и мы начали работать над интерактивной сессией PHP с шаблоном формы (имя, должность, любимый цвет и т. Д. c.). На этой неделе наша задача состоит в том, чтобы выбрать наш любимый цвет из формы, чтобы выражение цвета фона на странице процессора отображало тот же цвет. У нас есть главная страница php, таблица стилей php и css, и нам разрешено изменять код на странице процессора только для выполнения sh. Задание началось через неделю go, и я не разобрался с назначением через 2 дня. Я вставлю код для страницы процессора ниже, и, надеюсь, кто-то может помочь. Первая - это только часть цвета, а вторая - вся страница процессора.

// process and display the birthday and the color info...
print "<br><br><div class=\"label2\" input type=\"background-color\">Your birthday is:  $bday and<br><br><span>...this $favcolor is your favorite color</span></div>";

<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<html>

<head>
   <title>Sports Survey - Server page</title>
   <link rel="stylesheet" type="text/css" href="sportssurveystyle7BrandonMiller.css" />
</head>

<body>

<?php  session_start();

// grab form data from the caller out of the $_POST[] array...
// also, save the data to the $_SESSION[] array, so we can access it from the main script
// ... in the event of a reload due to an error...
$firstName = $_SESSION['firstname'] = $_POST['firstname'];
$lastName = $_SESSION['lastname'] = $_POST['lastname'];
$cel = $_SESSION['cel'] = $_POST['cel'];
$work = $_SESSION['work'] = $_POST['work'];
$email = $_SESSION['email'] = $_POST['useremail'];
$status = $_SESSION['status'] = $_POST['status'];
$football = $_SESSION['football'] = $_POST['footballcb'];
$basketball = $_SESSION['basketball']= $_POST['basketballcb'];
$boxing = $_SESSION['boxing'] = $_POST['boxingcb'];
$croquet = $_SESSION['croquet']= $_POST['croquetcb'];
$favcolor = $_SESSION['favcolor'] = $_POST['favcolor'];
$bday = $_SESSION['bday']= $_POST['bday'];
$badminton = $_SESSION['badminton'] = $_POST['badminton'];
$concerts = $_SESSION['concerts']= $_POST['concerts'];

$sportsCount = 0;
if ( $football == 1 )
   $sportsCount++;
if ( $basketball == 1 )
   $sportsCount++;
if ( $boxing == 1 )
   $sportsCount++;
if ( $croquet == 1 )
   $sportsCount++;

if ( $status == "full-time" && $sportsCount < 3 )
   {
   $_SESSION['sportserrfull'] = 1;
   $_SESSION['reload'] = 1;
   header("Location:./SportsSurveyMain7BrandonMiller.php");
   }
else if ( $status == "part-time" && $sportsCount < 2 )
   {
   $_SESSION['sportserrpart'] = 1;
   $_SESSION['reload'] = 1;
   header("Location:./SportsSurveyMain7BrandonMiller.php");
   }
else if ( $status == "intern" && $sportsCount < 1 )
   {
   $_SESSION['sportserrintern'] = 1;
   $_SESSION['reload'] = 1;
   header("Location:./SportsSurveyMain7BrandonMiller.php");
   }

// filter bad chars out of the $firstName variable, in order to prevent hacking... we would want to do this for any text field the user has access to!
$badchars = array("'", '"', '@', ' ', '-', '+');    // set up an array of bad characters
$okchars = array("", "", "", "", "", "");           // set up an array of good characters, to replace the bad characters with
$newfirstName = str_replace($badchars, $goodchars, $firstName);

if ( $newfirstName != $firstName )   // if the new firstName is not the same as the old firstName, invalid chars were detected...
   {
   print "<br><br><div class=\"label2\">Invalid chars detected in first name... original first name is: $firstName ... modified first name is: $newfirstName</div>";
   $firstName = $newfirstName;
   }

print "<br><br><div class=\"label1\">Thanks for submitting!</div>";


// process and display the name info...
print "<br><br><div class=\"label2\">You said your first name is $firstName and your last name is $lastName</div>";

// process and display the employment status info...
print "<br><br><div class=\"label2\">You said your employment status is: $status</div>";

// open up another label2 div and then processs and display the sports info...
print "<br><br><div class=\"label2\">Regarding sports, you said that you like: ";

// initialize a variable to keep count of how many sports the user likes...
$sportCount = 0;

// analyze the sports checkboxes, one by one...
if ( $football == 1 )
   {
   print "Football... ";
   $sportCount++;
   }
if ( $basketball == 1 )
   {
   print "Basketball... ";
   $sportCount++;
   }
if ( $boxing == 1 )
   {
   print "Boxing... ";
   $sportCount++;
   }
if ( $croquet == 1 )
   {
   print "Croquet... ";
   $sportCount++;
   }

if ( $sportCount == 0 )
   print "no sports at all.";
else if ( $sportCount == 1 )
   print "&nbsp;&nbsp;&nbsp;(You like only 1 sport).";
else
   print "&nbsp;&nbsp;&nbsp;(You like $sportCount sports).";

print "</div>";  // thats the end of the sports div...

// process and display the birthday and the color info...
print "<br><br><div class=\"label2\" input type=\"background-color\">Your birthday is:  $bday and<br><br><span>...this $favcolor is your favorite color</span></div>";

// process and display the badminton and concerts info...
print "<br><br><div class=\"label2\">Your level of expertise in badminton is: $badminton and you rated your enjoyment of concerts as: $concerts";

// process and display the badminton and concerts info...
if ( $badminton <= 4 )
print "<br><br><div class=\"beginner\">You are a beginner at badminton... level: $badminton </div>";
else if ( $badminton <= 7 )
print "<br><br><div class=\"novice\">You are a novice at badminton... level: $badminton </div>";
else
print "<br><br><div class=\"expert\">You are an expert at badminton... level: $badminton </div>";

// reload my survey input page...
print "<br><br><br><form action=\"SportsSurveyMain7BrandonMiller.php\" method=\"post\">";
print "<input type=\"hidden\" name=\"nada\" value=\"nada\">";
print "<input type=\"submit\" value=\"Continue\"></form><br><br>";

// end of the PHP script
?>

</body>

</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...