dsgwdigu84950 2012-04-08 13:03
浏览 29
已采纳

一张有3个提交的表格; 如何保存最终提交的数据?

I have created a PHP form which requires the user to select a postcode from a list of postcode values.

The user presses submit two times: - once to go to address select menu which will display a select drop-down with values - second presses "ok" button to select the address corresponding to his postcode value

I need to keep the value of the selected postcode value for when the form gets submitted. I have tried setting up the postcode drop-down value chosen in a SESSION... but it gets lots when user presses form submit.

How can I keep all the form values even after refreshing the page when the user presses one of the submits?

  • 写回答

2条回答 默认 最新

  • douwen7475 2012-04-08 13:22
    关注

    "How can I keep all the form values even after refreshing the page when the user presses one of the submits?"

    Reading your question I didn't understand if each of the form submits actually gets submitted to the server, but I'm going to assume so. I'm also assuming you're trying to use PHP sessions to accomplish this.

    When the user submits the form, save the values server-side in a PHP session

    //Start the session
    session_start();
    //Save the values
    $_SESSION["foo"] = $_POST["bar"];
    ...
    

    If, after choosing the address, the user gets redirected to the initial form and you want to populate that:

    //Start the session
    <?php
       session_start();
    ?>
    
    <!-- Populate HTML form based on previously submitted values -->
    <input type="text" name="foo" value="<?php echo $_SESSION["foo"] ?>" />
    ...
    

    After the final submit you should have all the submitted values saved in the $_SESSION array. Don't forget to always session_start() before trying to handle anything session related.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大