入力フォームに入力した値を確認表示画面で表示されないです。初期入力フォームで値を入力したあと、submit押すと確認表示画面に情報を送れるようになっています。
キャッシュデータを消去して試しても確認表示画面で表示されないです。
コードの概要
未入力エラーの場合はPHPエラーと同時にscriptのアラートエラーも出すように2重実装してあります。
■入力フォームのPHP page1.php
https://jdsatysdf.info/reviwe/osusume/page1.php
php
1<?php 2session_start(); 3 4$errors = array(); 5if ($_POST) { 6 7$email = filter_input(INPUT_POST, 'email'); 8 9if (empty($email)) $errors[] ="未入力 "; 10if (count($errors) === 0) { 11 12$_SESSION['email'] = $email; 13 14/* 確認画面の表示, */ 15header('Location:https://jdsatysdf.info/reviwe/osusume/page2.php'); 16exit(); 17 } 18} 19 20if(isset($_GET['action']) && $_GET['action'] === 'edit'){ 21$email = $_SESSION['email']; 22} 23?> 24 25<body> 26 <form action="page2.php" method="post" id="form"> 27 <input type="text" class="form1" name="email" id="email" placeholder="例)ta.com" 28 value="<?php if(isset($email)){ echo $email; } ?>" /> 29 30 <button id="submit" type="submit" value="送信する">確認画面へ</button> 31 </form> 32 33<script> 34 // javaでエラーメッセージの表示 35 const form = document.querySelector('#form'); 36 const itemname = document.querySelector('#itemname'); 37 const email = document.querySelector('#email'); 38 form.addEventListener('submit', function(event) { 39 let msg = ""; 40 41 42 // scriptでエラーメッセージの表示 PHPと重複表示にしています。 43 if (email.value == "") msg += "未入力\n"; 44 if (msg != "") { 45 event.preventDefault(); 46 alert(msg); 47 } 48 }); 49 50 form.addEventListener('change', function() { 51 52 if (itemname.value != "") sessionStorage.setItem('itemname', itemname.value); 53 if (email.value != "") sessionStorage.setItem('email', email.value); 54 }); 55 56 //値を保持 57 itemname.value = sessionStorage.getItem('itemname'); 58 email.value = sessionStorage.getItem('email'); 59</script>
■確認表示画面php page2.php
php
1<?php 2session_start(); 3 4if(isset($_SESSION['name'])){ 5$email = $_SESSION['email']; 6} 7 8$_SESSION['token'] = base64_encode(openssl_random_pseudo_bytes(48)); 9$token = htmlspecialchars($_SESSION['token'], ENT_QUOTES); 10?> 11 12<body> 13 <form action ="" method ="post" name="doui_form"> 14 <input type ="hidden" name ="token" value ="<?php echo $token ?>"> 15 <div class="inputtitle">アドレス<?php echo $email; ?></div> 16 </form> 17</body> 18 19 20 21

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/10/08 07:13