0
I’m picking up a form with AJAX and Jquery and sending for treatment in a file PHP by name getPDF, in this form there are several checkboxes with different values however name and class equal (name='check[]
' and class='toggle-check
').
I know how to get the values in the checkbox fields checked with foreach, however there is some way that I get all values of all checkbox form independent of whether they are checked or not ?
PHP code (Where only checkbox checked are handled):
<?php
include_once "../Data/config.php";
foreach($_POST['check'] as $check) {
$result="SELECT * FROM indicador WHERE nome = '".$check."'";
$resultado = mysqli_query($dbc,$result);
while($row_indicador = mysqli_fetch_assoc($resultado)) {
echo'teste com sucesso ';
}
}
Javascript code that sends the values to the PHP
jQuery(document).ready(function(){
//envio o formulário para tratamento no getPDF.php
jQuery('#formVerIndicadores').submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: "POST",
url: "getPDF.php",
data: dados,
success: function(data)
{
$('#resultadoPesquisaIndicador').html(data);
}
});
return false;
});
});
Html code that was generated by PHP :
<form id='formVerIndicadores' method='post'>
<tr>
<td>Carne bovina de corte</td>
<td>
<div><input class="toggle-check 1" name="check[]" id="" value="Carne bovina de corte" type="checkbox"><span></span></div>
</td>
</tr>
<tr>
<td>Bovino (kg*Pa)</td>
<td>
<div><input class="toggle-check 2" name="check[]" id="" value="outro valor qualquer" type="checkbox"><span></span></div>
</td>
</tr>
//Pode ter N checkboxes dependendo da seleção em outro arquivo php
<input type='button' value='Enviar'/>
</form>
is the same thing, the point is that if it’s not marked it comes as
false
– Rafael Augusto
And how do I get it back in my php ?
– Vinicius Gularte
how are checkboxes mounted on the form? What is the form code like? You can post the form page code?
– user60252
Added, the only thing that changes from one checkbox to another is the other class that increases by 1 in 1
– Vinicius Gularte
Adding manually? Or with a while php?
– user60252
While browsing the database, you want me to put the part that generates the checkboxes ?
– Vinicius Gularte
Only the while line is good, can be in comment
while .....{
– user60252