У меня есть форма, где у меня есть поля формы с одинаковыми именами, но с разными значениями.
<p><input type="checkbox" name="answer" value="D">
<b>A</b> When the router boots up, the Cisco IOS image is loaded from a secured FTP location</p>
<p><input type="checkbox" name="answer" value="A">
<b>B</b> The Cisco IOS image file is not visible in the output of the show flash command.</p>
<p><input type="checkbox" name="answer" value="C">
<b>C</b> The Cisco IOS image is encrypted and then automatically backed up to the NVRAM.</p>
<p><input type="checkbox" name="answer" value="B">
<b>D</b> The Cisco IOS image is encrypted and then automatically backed up to a TFTP server.</p>
моя идея состоит в объединении значений отмеченных ящиков с использованием той же переменной $ _POST, но php сохраняет только последнее значение сверху вниз. есть ли способ сделать это или мне нужно изменить "ответ" на 1, 2, 3 и объединить их в другую переменную?
задайте имена для ответа [], а переменная $ _POST ['answer'] будет массивом выбранных значений. Вот так:
<input type="checkbox" name="answer[]" value="C">
Измените ответ на "answer []". Это должно создать массив элементов, которые будут переноситься в почтовом контенте.
Использовать name="answer[]"
в HTML
<form method="post" action="test.php">
<p><input type="checkbox" name="answer[]" value="D">
<b>A</b> When the router boots up, the Cisco IOS image is loaded from a secured FTP location</p>
<p><input type="checkbox" name="answer[]" value="A">
<b>B</b> The Cisco IOS image file is not visible in the output of the show flash command.</p>
<p><input type="checkbox" name="answer[]" value="C">
<b>C</b> The Cisco IOS image is encrypted and then automatically backed up to the NVRAM.</p>
<p><input type="checkbox" name="answer[]" value="B">
<b>D</b> The Cisco IOS image is encrypted and then automatically backed up to a TFTP server.</p>
<input type="submit">
В test.php
<?php
print '<pre>';
print_r($_POST['answer']); // $_POST['answer'] returns an array with checked checkbox
print '<pre>';
?>
name="answer[]"
.