How to pick up and display PHP deselected checkbox data

Asked

Viewed 22 times

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:

inserir a descrição da imagem aqui

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 the foreach doesn’t make sense, you’re validating isset($_POST['nome']), when, to be inside the foreach, 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?

  • Unless you send the value’S' or 'N' to the post ai yes you can treat

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.