アプリ版:「スタンプのみでお礼する」機能のリリースについて

HTMLで下記の通りのプログラムを書きました。

動きとしては戻るボタンを押したら値は入力したままの状態になってほしいのですが、何故かクリアされて上手くいきません。

どうしてなのかご教授お願い致します。


下記のプログラムは一部抜粋しています。
また、プログラムは二つあり、二番目は戻り先のプログラムです。

<body>
<div class="content">
<h1>以下の情報を登録しますが、よろしいでしょうか?</h1>
<form action="c_regi_ans.php" method="get">
<div class="control">
<label for="C_num">顧客番号</label>
<input readonly id="C_num" type="number" name="C_num" value="<?php print($_GET['C_num']);?>">
</div>
<div class="control">
<label for="C_name">顧客名</label>
<input readonly id="C_name" type="text" name="C_name" value="<?php print($C_name);?>">
</div>
<div class="control">
<label for="C_phon">顧客電話番号</label>
<input readonly id="C_phon" type="tel" name="C_phon" value="<?php print($C_phon);?>">
</div>
<div class="control">
<label for="C_sa">顧客住所</label>
<input readonly id="C_sa" type="text" name="C_sa" value='<?php print($C_sa);?>'>
</div>
<div class="control">
<input type="submit" value="確定">
</div>
</form>
<form action="c_regi.php" method="get">
<input type="hidden" name="C_name" value="<?php print($C_name); ?>">
<input type="hidden" name="C_num" value="<?php print($C_num); ?>">
<input type="hidden" name="C_phon" value="<?php print($C_phon); ?>">
<input type="hidden" name="C_sa" value="<?php print($C_sa); ?>">
<div class="control">
<input type="submit" value="戻る">
</div>
</form>
</div>
</body>


戻り先のプログラム(一部抜粋)

<h1>顧客登録</h1>
<form action="c_regi_veri.php" method="GET" name="form1" onSubmit="return formcheck()">
<div class="control">
<label for="C_num">顧客番号(半角数字のみ入力可)<span class="required">必須</span></label>
<p id="C_num" style="display: none; color: red;"> 【入力して下さい】</p>
<input pattern="[1-9][0-9]*" id="C_num" type="number" name="C_num" value=""/ onChange="check0() , check4()">
</div>
<div class="control">
<label for="C_name">顧客名(全角文字のみ入力可)<span class="required">必須</span></label>
<p id="C_name" style="display: none; color: red;"> 【入力して下さい】</p>
<input pattern="[^\x20-\x7E]*" id="C_name" type="text" name="C_name" value="" onkeyup = "this.value = this.value.replace(/[ -~1234567890]/g, '')" onChange="check1() , check5()"/>
</div>
<div class="control">
<label for="C_phon">顧客電話番号(半角数字のみ入力可、11桁まで入力可、ハイフンなし)<span class="required">必須</span></label>
<p id="C_phon" style="display: none; color: red;"> 【入力して下さい】</p>
<input pattern="^[0-9]+$" id="C_phon" type="tel" name="C_phon" value=""/ onChange="check2() , check6()">
</div>
<div class="control">
<label for="C_sa">顧客住所<span class="required">必須</span></label>
<p id="C_sa" style="display: none; color: red;"> 【入力して下さい】</p>
<input id="C_sa" type="text" name="C_sa" value=""/ onChange="check3() , check7()">
</div>
<div class="control">
<input type="submit" value="登録">
</div>
</form>
<form action="menu.php" method="GET">
<div class="control">
<input type="submit" value="メニューへ">
</div>
</form>
</div>
</body>
</html>

A 回答 (2件)

> 質問ですが、c_regi.php側のHTMLの各項目value属性には


> value=“‘.$_get[‘name’].’”といった感じでいいんですか?
value="<?php print($_GET['C_name']); ?>"
です。

ページ遷移をいずれのページもGETパラメーターでやりとりしているので、セキュリティ上いいとは言えませんが、それは今回質問とは別な話です。
マズいことを理解したいなら、ページ遷移後、URLに付与されたパラメーターを意図的に書き換えてアクセスしてみてください。

また、これも全ページに言えることですが、入力値にHTML、JavaScriptなどのコードが入れられた時、意図しない動作を及ぼします。(XSS)
https://ja.wikipedia.org/wiki/%E3%82%AF%E3%83%AD …
対策としてhtmlspecialchars()の検討や、何かフレームワークを使っているならそれに準じた対応が必要になります。
    • good
    • 1
この回答へのお礼

指摘していただきありがとうございます。
セキュリティに関してはのちにちゃんと勉強しておきます。
いろいろとありがとうございました。

お礼日時:2021/02/01 17:36

戻るボタンを押した時、c_regi.php側のHTMLの各項目value属性に、渡ってきた値を設定していないからですね。

    • good
    • 0
この回答へのお礼

回答ありがとうございます。
質問ですが、c_regi.php側のHTMLの各項目value属性には
value=“‘.$_get[‘name’].’”といった感じでいいんですか?

こんな感じでやると何も変わらなかったです。

お礼日時:2021/02/01 12:09

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています


このQ&Aを見た人がよく見るQ&A