0
I have a table where a column consists of checkbox. In the future, the status of these checks will be saved in a database for automatic loading, but at the moment, for the purpose of testing and also facilitating the understanding of the question, I just need to show the status of this check and its value. This is my PHP code so far:
<?php
// Verifica se usuário escolheu algum check
if(isset($_POST["nome"]) {
echo "Os checks que você escolheu são: ";
// Faz loop pelo array do check
foreach ($_POST["nome"] as $check) {
//pega o status do checkbox
$_POST["nome"] = isset($_POST["nome"]) ? "checked" : null;
$valor = $_POST["nome"];
echo "$valor $check";
}
}
When I SELECT a check it shows right:
However, DESELECT does not show anything. I don’t know much about PHP, but I imagine it’s like I haven’t selected anything. I need a solution as soon as possible.
P.S.: In the table there is a common form action directing to the PHP page and inside a input type:checkbox
with onchange="this.form.submit()"
.
HTML does not send
checkbox
not selected. In addition, the code within theforeach
doesn’t make sense, you’re validatingisset($_POST['nome'])
, when, to be inside theforeach
, the value must have already been defined. What is your real intention, it is very likely that another solution will be appropriate to your problem?– Gabriel Heming
Unless you send the value’S' or 'N' to the post ai yes you can treat
– adventistaam