首页 > 解决方案 > 创建通知并将输入列表存储在框中

问题描述

<?php

    session_start();


    function submitform()
    {
        if(isset($_POST['submit']))
        {
            notify('positive','hello'.$_POST['name']);
        }
    }

    function notify($type = 'neutral', $message = 'Hello')
    {
        $_SESSION['notify']['type'] = $type;
        $_SESSION['notify']['message'] = $message;

    }

    function notifcation()
    {
        if(isset($_SESSION['notify']))
        {
            $type = $_SESSION['notify']['type'];
            $message = $_SESSION['notify']['message'];

            $html = '<div class="notify'.$type.'">'.$message.'</div>';


            echo $html;
        }
    }

    ?>

测试.php

<?php require 'functions.php' ?>

<html>
<head>
    <title>Notification bar</title>
    <link rel="stylesheet" href="" />
</head> 
<body>

    <div id="container">

    <?php notification(); ?>  //error

        <h1>Test</h1>
        <h2>Notifcation</h2>

        <form action="<?php submitForm(); ?>" method="post">

            <label for="name">Name</label>
            <input type="text" name="name" id="name" />

            <input type="submit" name="submit" id="submit" value="Send" />

        </form>

    </div>

</body>
</html>

我正在为我的服装网站创建通知,如果管理员帐户创建新产品,它将显示在新实体的框(主页)中。所以我创建了一个输入,它将输出表单中写入的内容,但是为了在我的主页中显示它,我将如何创建一个包含添加产品历史的存储框,因为我现在的输出只显示何时我输入了一个文本并按下回车键,只有在插入另一个文本之后。

标签: phphtml

解决方案


推荐阅读