提交表单后,应运行一个名为 itgeneratePage.php 的 PHP 脚本。它应该使用表单中的值为标题、顶级标题和正文创建 HTML 元素。该脚本还应使用表单中的值为文本的背景颜色和字体颜色设置 CSS 属性。我很困惑为什么我的脚本没有通过
<!DOCTYPE HTML>
<html>
<title>webPageGenerator</title>
<head>
</head>
<body>
<br />
<h1>Webpage generator</h1>
<br />
<form action="itgeneratePage.php" method="post">
<p>page name: <input type="text" name="pagename"/></p>
<p>background color: <input type="text" name="bgcolor"/></p>
<p>font color: <input type="text" name="fontcolor"/></p>
<p>your text: <input type="text" name="content"/></p>
<p><input type="submit" value="create webpage!"/></p>
</form>
</body>
</html>
itgeneratePage.php
<?php
//Later configure this in main php config file
error_reporting(E_ALL);
//header("Content-type: text/css");
$bgcolor = $_POST['bgcolor'];
$color = $_POST['fontcolor'];
//$dkgreen = '#008400';
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo$_POST['pagename']?></title>
<style type="text/css">
body {
background: <?=$bgcolor?>;
color: <?=$color?>;
}
</style>
</head>
<body>
<h1><?php echo$_POST['content']?><h1>
<br /><hr/>
</body>
</html>
最佳答案
你只是犯了一个小错误。不过别担心,
答案如下:
只需将 css 更改为:
body {
background: <?='#' . $bgcolor?>;
color: <?='#' . $color?>;
}
关于php - 脚本应该为背景颜色、字体颜色和使用表单中的文本值设置 CSS 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36375033/