問題 1:データベースから取得したイベントのリストを含むフォームがあり、その横に顧客が出席を登録するためのチェックボックスがあります。特別な要件を示す追加のチェックボックスと、詳しく説明するテキスト フィールドがあります (「はいの場合、追加の詳細を提供してください...」)。
顧客が参加しているすべてのイベントを、イベント ID、特別な要件の「はい/いいえ」、およびそのような要件の詳細を含む多次元配列に保存したいと考えています。私は順調に進んでいると思いました:
<form id="bookingform" method="post" action="booking-details.php">
<fieldset>
<legend>Personal information</legend>
<div class="bookingitem">
<label for="firstname">First name</label> <input type="text" name="firstname" id=
"firstname" />*<br />
</div>
<div class="bookingitem">
<label for="surname">Surname</label> <input type="text" name="surname" id=
"surname" />*<br />
</div>
<div class="bookingitem">
<label for="company">Company</label> <input type="text" name="company" id=
"company" />*<br />
</div>
</fieldset>
<fieldset>
<legend>Which exhibition(s)?</legend>
<div class="bookingitem">
<?php
$venues_query="SELECT exhibitions.exhib_id AS exhib_id, venues.venue_name AS venue, DATE_FORMAT(exhibitions.exhib_date, '%d/%m/%y') AS date FROM venues, exhibitions WHERE exhibitions.venue_id = venues.venue_id AND (exhibitions.exhib_date>=CURDATE())ORDER BY exhibitions.exhib_date";
$venues_result=mysql_query($venues_query);
while($venues=mysql_fetch_array($venues_result, MYSQL_ASSOC)){
echo '<input type="checkbox" name="registrations['.$venues['exhib_id'].'][id]" /> '.$venues['venue'].' - '.$venues['date'].'<br/>';
echo '<input type="checkbox" name="registrations['.$venues['exhib_id'].'][requirements]" />Special requirements?<br/>';
echo 'If yes, please give more details... <input type="text" name="registrations['.$venues['exhib_id'].'][requirements_details]" />';
}
mysql_close();
?>
</div>
</fieldset>
<fieldset>
<legend>Terms and conditions:</legend>
<p>T&Cs here</p>
<div>
<input type="submit" class="buttons" name="submit" value="Submit" />
</div>
</fieldset>
</form>
...しかし、私がするときvar_dump($_POST['registrations']);
、私は得ているだけです:
array(4) { [0]=> string(5) "00132" [1]=> string(5) "00140" [2]=> string(5) "00135" [3]=> string(5) "00136" }
5 桁の数字はデータベースから取得したイベント ID ですが (この例では 4 つのイベントを登録しています)、他の情報は保存されていないようです。私はそれが盲目的に明白であることを期待していますが、誰かが私が間違っている場所を見つけることができますか?
次のコードを使用して、 (この例のように)値をループできるようにしたい:
foreach ( $_POST['registrations'] as $registration )
{
echo '$registration[id]';
echo '$registration[requirements]';
echo '$registration[requirements_details]';
// etc
}
問題 2:特別な要件のボックスにチェックを入れると、詳細ボックスにも記入されるようにしたいと思います。以前は、フォームの各部分に 3 つの個別の配列を用意し、count()
ティック数と完了した入力ボックス数を調べていました。一致しない場合、フォームは処理されません。ただし、これを達成するためのはるかに簡単な方法があると確信しており、アドバイスをいただければ幸いです。