pass value of a form via filter_input ()

0

I have a form that contains the following fields:

 ...
    <input type="checkbox" name="Cadastro[]" value="S"> Sim
    <input type="checkbox" name="Cadastro[]" value="N"> Não
   ....

I'm retrieving field values using filter_input (). For example:

$nomeUsuario = filter_input(INPUT_POST,"NomeUsuario",FILTER_DEFAULT);

In the case of the fields Record and Edit, how are array, how would I get the values like the filter_input and play into a function?

function executar($cadastro){
   ....
}

I'm using it that way, but I'm not getting it:

$cadastro = filter_input_array(INPUT_POST,"Cadastro");

When giving var_dump($cadastro); , it returns:

  

bool (false)

And when I use $_POST["Cadastro"]; , it returns only the first value:

$cadastro = $_POST["Cadastro"];

function testar($cadastro){
    foreach($cadastro as $teste){
      $valor = $teste."<br>";
    }
  return $valor;
 }
}
echo testar($cadastro); // Retorno S
    
asked by anonymous 18.07.2017 / 15:31

1 answer

1

I was able to solve with the global variable $ _POST. I created a $ value variable with a null value before the loop and concatenated the variable inside the loop. Follow below:

$cadastro = $_POST["Cadastro"];

function testar($cadastro){
    $valor = "";
    foreach($cadastro as $teste){
      $valor .= $teste."<br>";
    }
  return $valor;
 }
}
echo testar($cadastro);
    
18.07.2017 / 16:19