【问题标题】:script should set CSS properties for background color, font color and using text values from the form脚本应该为背景颜色、字体颜色和使用表单中的文本值设置 CSS 属性
【发布时间】:2016-07-22 08:44:36
【问题描述】:

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

【问题讨论】:

  • 尝试在你的颜色名称后使用重要,例如背景:=$bgcolor?>!important;

标签: php html css forms


【解决方案1】:

你只是犯了一个小错误。不过不用担心,

下面是答案:

只需将 css 更改为:

 body {
        background: <?='#' . $bgcolor?>;
        color: <?='#' . $color?>;
 }

【讨论】:

  • 有效点。那么就必须这样处理。
猜你喜欢
  • 2021-12-03
  • 2017-03-26
  • 2013-07-29
  • 1970-01-01
  • 2011-02-14
  • 1970-01-01
  • 2019-03-07
  • 2019-04-22
  • 1970-01-01
相关资源
最近更新 更多