dongyong2063
dongyong2063
2016-03-18 08:46

刷新页面后内容消失(Wordpress)

已采纳

I am developing a plugin where i have a form and a submit button. The form-action is the_permalink(). When the user clicks on the submit-button, a message ("hello") should be visible, which works fine with this code:

if(isset($_POST['submit']))
{
   display();
}
function display()
{
    echo "hello";
}

But if i refresh the page, the message is gone. Does anybody know how to fix this to that the message stays there?

This has porbably something to do with that i compare $_POST with 'submit', which is not given after a refresh...

Thanks for your help!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dtlab08822 dtlab08822 5年前

    Please try following code

       session_start();
    if(isset($_POST['submit']))
    {
       $display_val = display();
       $_SESSION['display_val'] = $display_val;
    }
    
    if(isset($_SESSION['display_val']))
    {
        echo $_SESSION['display_val'];
    }
    
    
    function display()
    {
        return "hello";
    }
    
    点赞 评论 复制链接分享

相关推荐