I'm getting a form with AJAX and Jquery and sending for treatment in a PHP file with name getPDF , in this form there are several checkboxes with different values, but name and class are equal ( name = ' check[]
' and class = ' toggle-check
' ).
I know how to get the values in the checked checkbox fields with foreach , but is there any way I can get all of the values from all the checkboxes of the form regardless of whether they are checked or not?
PHP code (where only checked checkboxes 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 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 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>