doupijin0397 2015-07-08 22:53
浏览 217
已采纳

HTML表单post方法和自动刷新PHP页面

In my html page, I have a php iframe that gets its variables from the form using post method. This works fine.

My problem is this: I would like the php iframe to auto-refresh (which it does), but , understandably, I get undefined index errors from php the first time the iframe auto-refreshes.

Is there some way (preferably using only php/html) to allow the iframe to hold on to the variables from the html form after the first load of the php iframe? Isset doesn't seem to be the answer to my problem

  • 写回答

1条回答 默认 最新

  • dongliushui2001 2015-07-08 23:05
    关注

    Here's a very simple way of accomplishing what you're after:

    <?php
    
    // Starts a session
    session_start();
    
    // Gets a variable via $_POST if present and caches it in $_SESSION
    // If it doesn't exist in $_POST or $_SESSION, return null
    function get_variable( $name )
    {
        if( isset( $_POST[$name] ) )
        {
            $_SESSION['cache_'.$name] = $_POST[$name];
        }
        return ( isset( $_SESSION['cache_'.$name] ) ? $_SESSION['cache_'.$name] : null );
    }
    
    // Get these values from the form on the cache
    $value_a = get_variable('field_name_a');
    $value_b = get_variable('field_name_b');
    $value_c = get_variable('field_name_c');
    
    // One the values is missing
    if( is_null( $value_a ) || is_null( $value_b ) || is_null( $value_c ) )
    {
        // Display an error message or whatever else
    }
    // All values are present
    else
    {
        // Use the variables however you were before
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 笔记本上移动热点开关状态查询
  • ¥70 类鸟群Boids——仿真鸟群避障的相关问题
  • ¥15 CFEDEM自带算例错误,如何解决?
  • ¥15 有没有会使用flac3d软件的家人
  • ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
  • ¥15 docker实践项目
  • ¥15 利用pthon计算薄膜结构的光导纳
  • ¥15 海康hlss视频流怎么播放
  • ¥15 Paddleocr:out of memory error on GPU
  • ¥30 51单片机C语言数码管驱动单片机为AT89C52