This commit is contained in:
FlyInTheBox 2023-03-01 14:23:11 +01:00
parent 288c09d171
commit 51dc25d05b

View file

@ -13,8 +13,10 @@
<legend>Liczby</legend> <legend>Liczby</legend>
<?PHP <?PHP
$arr = range(0, 100, 10); $arr = range(0, 100, 10);
foreach ($arr as $value) { foreach ($arr as $value) {
echo '<label for="check"><input type="checkbox" name="check[]" value="' . $value . '" id="box' . $value . '">' . $value . '</label>'; $checked = (!empty($_POST['check']) && in_array($value, $_POST['check'])) ? 'checked':'';
echo '<label for="check"><input type="checkbox" name="check[]" value="' . $value . '" id="box' . $value . '" '.$checked.'>' . $value . '</label>';
} }
echo '<br><button type="submit">Wyślij</button>'; echo '<br><button type="submit">Wyślij</button>';
?> ?>
@ -23,11 +25,9 @@
if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($_POST['check'])) { if (empty($_POST['check'])) {
echo 'Nie wybrano żadnych liczb.'; echo 'Nie wybrano żadnych liczb.';
} else { }
echo 'Wybrano liczby: '; else {
foreach ($_POST['check'] as $value) { echo 'Wybrano liczby: '.implode(', ',$_POST['check']).'.';
echo $value . ', ';
}
} }
} }
?> ?>