2 回答
TA贡献2051条经验 获得超10个赞
HTML:
<form method="post" action="test.php">
<p class="center">Vyberte školenie</p>
<label class="container riadok"><p for="document1" class="dolava">§20 Poučená osoba</p>
<input type="checkbox" name="document[1]" value="document1" id="document1">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">Aktualizácia: §21 AŽ §24</p>
<input type="checkbox" name="document[2]" value="document2" id="document2">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">§21 Elektrotechnik</p>
<input type="checkbox" name="document[3]" value="document3" id="document3">
<span class="checkmark"></span>
</label>
<label class="container riadok"><p for="document" class="dolava">§24 Revízny technik</p>
<input type="checkbox" name="document[4]" value="document4" id="document4">
<span class="checkmark"></span>
</label>
<p class="center">Vyplňte osobné údaje</p>
<input type="text" name="name" id="name" class="form-control" placeholder="Meno">
<input type="text" name="email" id="email" class="form-control" placeholder="Email">
<input type="tel" name="phone" id="phone" class="form-control" placeholder="Telefónne číslo" pattern="[0-9]+" title="Zadajte iba čísla." required="required">
<input type="hidden" name="send" value="1" />
<button type="submit" value="SEND" id="submit" class="btn btn-primary"> ODOSLAŤ PRIHLÁŠKU</button>
</form>
PHP:
<?php
$translation_table = array(1 => '§20 Poučená osoba', 2 => 'Aktualizácia: §21 AŽ §24'); // fill it yourself, I am not going to do that, just add another numbers and labels
if(isset($_POST['document'])){
foreach($_POST['document'] as $id => $val){
echo $translation_table[$id] . " = " . $val . "<br />";
}
}
?>
这应该可以帮助你解决你的问题。
TA贡献1806条经验 获得超5个赞
标签不会在表单提交中自动发送。
您可以更改 HTML,以便将标签包含在复选框值中。
<label class="container riadok"><p for="document1" class="dolava">§20 Poučená osoba</p>
<input type="checkbox" name="document[document1]" value="§20 Poučená osoba<" id="document1">
然后在 PHP 中你可以:
foreach ($documents as $key => $label) {
if (isset($documents[$key])) {
$message = "ŠKOLENIE: $label";
}
}
$message另外,每次循环都会覆盖。您应该附加它,而不是替换它。
$message .= "
ŠKOLENIE: $label
";
- 2 回答
- 0 关注
- 92 浏览
添加回答
举报