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 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?