0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

問い合わせフォームの確認画面で「戻る」ボタンをクリックして入力画面に戻ると、入力データが消えている (Firefoxのみ)

Posted at

環境

JQuery 1.12.4
PHP 7.4

経緯

問い合わせフォームで入力したデータが確認画面から戻る際に、消えていることがあったので。メモです。
ボタン自体は下記のようなもので、ここでは入力画面へ戻った際のデータの保持は history.back() でしています。

# 確認画面
<?php
session_start();
以下、session処理
?>
<dl>
  <dt>氏名</dt>
  <dd><?=htmlspecialchars($post['name'])?></dd>
</dl>

<div class="btn>
  <button type="button" onclick="history.back()">入力画面へ戻るボタン</button>
</div>
# 入力画面
<?php session_start();?>
<dl>
  <dt><label for="name">氏名</label></dt>
  <dd><input id="name" type="text" name="name" required></dd>
</dl>

テストしたところ、Chrome、Edgeは問題なく、Firefoxの場合のみで入力画面へ戻った際に入力データが消失していました。

解決

下記のように、入力画面で使用していなかった不要な session_start() を削除後、キャッシュ削除して閲覧するとFireFoxも問題なく動作しました。

# 入力画面
<?php ?>
<dl>
  <dt><label for="name">氏名</label></dt>
  <dd><input id="name" type="text" name="name" required></dd>
</dl>

恐らくですが、ブラウザによってキャッシュを読み込む順番が違うのかと思います。
皆さんも不要なコードは削除しましよう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?