php - 脚本应该为背景颜色、字体颜色和使用表单中的文本值设置 CSS 属性

标签 php html css forms

提交表单后,应运行一个名为 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/

相关文章:

php - PHP 网站安全问题? (可能也适用于 ASP/Rails/等)

php - 我们可以在一个域中使用两个 WordPress 门户吗?

javascript - 平滑滑动背景图片

javascript - 按住按钮连续滚动 ReactJS

html - 为什么父高度与内部图像高度不同?

javascript - 结合 php 变量和 js 参数

javascript - 如何在 IF 语句中使用 (this) 选择元素

javascript - 为什么我的 localStorage.setItem() 和 localStorage.getItem() 没有存储值?

css - 使用 CSS3 模糊滤镜时图像周围出现白色模糊?

javascript - 基于上下文的隐藏