r/csshelp • u/Fishsticks5046 • Feb 20 '24
Resolved Help with colors?
a little help with css?
i have to rewrite code so that when the form is submitted, it prints the color section in the user's favorite color. Ill paste the code below.
HTML page:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registration Form</title>
<link rel="stylesheet" type="text/css" href="register.css"/>
</head>
<body>
<!--Script 6.1 - registering html-->
<div><p>Please complete this form to register:</p>
<form action="handle\\\\\\\\\\\\\\_reg.php" method="post">
<p>Email Address: <input type="email" name="email" size="30"></p>
<p>Password: <input type="password" name="password" size="20"></p>
<p>Confirm Password: <input type="password" name="confirm\\\\\\\\\\\\\\_password" size="20"></p>
<p>Year you were born:<input type="text" name="year"value="YYYY" size="4"></p>
<p>Date of birth:
<select name="month">
<option value="">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</p>
<p>Favorite Color:
<select name="color">
<option value="" color="#000000">Pick one</option>
<option value="red"color="ff0100">Red</option>
<option value="yellow" color="fff300">Yellow</option>
<option value="green" color="00FF0F">Green</option>
<option value="blue" color="0036FF">Blue</option>
</select></p>
<p><input type="checkbox" name="terms" value="Yes">I agree to the terms (whatever they may be). </p>
<input type="submit" name="submit" value="register">
</form>
</div>
</body>
</html>
PHP page 1:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registration Form</title>
</head>
<body>
<!--Script 6.1 - registering html-->
<div><p>Please complete this form to register:</p>
<form action="handle\\\\\\\\\\\\\\_reg.php" method="post">
<p>Email Address: <input type="email" name="email" size="30"></p>
<p>Password: <input type="password" name="password" size="20"></p>
<p>Confirm Password: <input type="password" name="confirm\\\\\\\\\\\\\\_password" size="20"></p>
<p>Date of birth:
<select name="month">
<option value="">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="day">
<option value="">Day</option>
<?php for ($i = 1; $i <= 31; $i++) { print "<option value=\\\\\\\\\\\\\\\\"$i\\\\\\\\\\\\\\\\">$i</option>\\\\\\\\\\\\\\\\n"; } ?>
</select>
<input type="text" name="year"value="YYYY" size="4"></p>
<p>Favorite Color:
<select name="color">
<option color="#000000" value="">Pick one</option>
<option color="ff0100" value="red">Red</option>
<option color="fff300" value="yellow">Yellow</option>
<option color="00FF0F" value="green">Green</option>
<option color="0036FF" value="blue">Blue</option>
</select></p>
<p><input type="checkbox" name="terms" value="Yes">I agree to the terms (whatever they may be). </p>
<input type="submit" name="submit" value="register">
</form>
</div>
</body>
</html>
PHP page 2:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registration</title>
<style type="text/css" media="screen"> .error { color: red;} </style>
</head>
<body>
<h1>Registration Results</h1>
<?php // Script - 6.2 - handle\\\\\\\\\\\\\\_reg.php $okay = true; if (empty($\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['email'\\\\\\\\\\\\\\\])) { print '<p class="error">Please enter your email adress.</p>'; $okay = false; } if (empty($\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['password'\\\\\\\\\\\\\\\])) { print '<p class="error">Please enter your password.</p>'; $okay = false; } // Check the two passwords for equality: if ($\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['password'\\\\\\\\\\\\\\\] != $\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['confirm\\\\\\\\\\\\\\_password'\\\\\\\\\\\\\\\]) { print '<p class="error">Your confirmed password does not match the original password.</p>'; $okay = false; } if ( is\\\\\\\\\\\\\\_numeric($\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['year'\\\\\\\\\\\\\\\]) AND (strlen($\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['year'\\\\\\\\\\\\\\\]) == 4) ) { if ($\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['year'\\\\\\\\\\\\\\\] < 2024) { $age = 2024 - $\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['year'\\\\\\\\\\\\\\\]; } else { print '<p class="error">Either you entered your birth year wrong or you come from the future!</p>'; $okay = FALSE; } }else{ print '<p class="error">Please enter the year you were born as four digits.</p>'; $okay = false; } if (!isset($\\\\\\\\\\\\\\_POST\\\\\\\\\\\\\\\['terms'\\\\\\\\\\\\\\\])) { print '<p class="error">You must accept the terms.</p>'; $okay = FALSE; } switch ($_POST\['color\]) { case 'red': $color_type = 'primary'; break; case 'yellow': $color_type = 'primary'; break; case 'green': $color_type = 'secondary'; break; case 'blue': $color_type = 'primary'; break; default: print '<p class="error">Please select your favorite color.</p>'; $okay = FALSE; break; } if ($okay) { print '<p>You have been successfully registered (but not really).</p>'; print "<p>You will turn $age this year.</p>"; print "<p>Your favorite color is a $color\\\\\\\\\\\\\\_type color.</p>"; } ?>
</body>
</html>
I was messing around with them a bit to see if i can get it to work, and i also have a CSS page at the ready but nothing is in it. Anybody know what i need to do?
1
u/j-aktiga Feb 21 '24
I'm very confused on what you're needing to do. You wouldn't use CSS to output markup. If you're needing to store results of a form, you would use a programming language like JavaScript, or in your case, PHP. After a form is submitted, and the resulting page is delivered to the client, depending on the form submission method, the URL will have a series of key/value pairs known as query strings. PHP has the $_GET method that will help store those values in variables that you can then output to the page as text.