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

アマゾンの評価のような星をクリックすると星の数が選択されるスター評価のコードを書いてます。
選択した評価で星の数の情報をphpで確認表示画面に送るコードを書いたのですが、submitを押して次の画面には行くのですが、phpが間違っていると思いますが、選択した星が表示されなくて困っています。

コードは星選択フォーム画面と確認画面の2つのコードを提示しています。


回答よろしくお願いいたします。

●星評価選択フォームの画面 b.php
<?php
session_start();
$errors = array();
if ($_POST) {
$rate = filter_input(INPUT_POST, 'rate');
if (empty($rate)) {
$errors[] = "評価をタップして下さい。";
} else {
// 各星のラジオボタンに評価値を設定
$_SESSION['rate'] = $rate;
header('Location:b2.php');
exit();
}
}

if (isset($_GET['action']) && $_GET['action'] === 'edit') {
$rate = $_SESSION['rate'];
}
?>
<style>
/* 選択の星のスタイル */
.rate-form {
display: flex;
flex-direction: row-reverse;
justify-content: flex-end;
}
.rate-form input[type=radio] {
display: none;
}
.rate-form label {
position: relative;
padding: 0 5px;
color: #ccc;
cursor: pointer;
font-size: 35px;
}
.rate-form label:hover {
color: #ffcc00;
}
.rate-form label:hover ~ label {
color: #ffcc00;
}
.rate-form input[type=radio]:checked ~ label {
color: #ffcc00;
}

<body>
<form action="b2.php" method="post" id="form">
<div class="rate-form">
<!-- 各星に評価値を設定 -->
<input id="star3" type="radio" name="rate" value="3">
<label for="star3">★</label>
<input id="star2" type="radio" name="rate" value="2">
<label for="star2">★</label>
<input id="star1" type="radio" name="rate" value="1">
<label for="star1">★</label>
</div>
<button id="submit" class="yohaku"></button>
</form>

●確認表示画面のPHP
<?php
session_start();

// セッションから評価値を取得
$rate = isset($_SESSION['rate']) ? $_SESSION['rate'] : '';

?>

<style>
/* 出力する星の大きさ */
.w {
font-size: 35px;
color: #ffcc00;
}
</style>

<body>
<form action="b3.php" method="post">
<div class="w"><?php echo $rate; ?></div>
<input type="submit" name="submit" value="評価を送信">
</form>
</body>

A 回答 (1件)

ヒントです。



●星評価選択フォームの画面 b.php
------------------------------------------------------------
$_SESSION['rate'] = $rate;
header('Location:b2.php');
------------------------------------------------------------
<form action="b2.php" method="post" id="form">
------------------------------------------------------------

●確認表示画面のPHP b2.php
------------------------------------------------------------
$rate = isset($_SESSION['rate']) ? $_SESSION['rate'] : '';
------------------------------------------------------------
    • good
    • 0

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

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


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