Colleagues.
I have the form below where I place the size, stock and if the product is to order. If it is to order, just select the product as shown below:
Thesizeandstockcanusuallypickupthevalues,buttheOrderfieldonlybringsmethefirstvalue.Seethecode:
<labelclass="checkbox-inline"><input type="checkbox" name="Encomenda[]" value="Sim" style="width: 20px">Encomenda</label>
JQuery that adds more fields:
<script type="text/javascript">
$(function () {
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
novoCampo = $("tr.linhas:first").clone();
novoCampo.find("input").val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
});
});
</script>
I'm getting it like this:
$tamanho = $_POST["Tamanho"];
$estoque = $_POST["Estoque"];
$encomenda = $_POST["Encomenda"];
$metodos->cadastrar($tamanho,$estoque,$encomenda);
The method class:
public function cadastrar($tamanho,$estoque,$encomenda){
.....
for($i = 0; $i <= count($tamanho); $i++){
if($estoque[$i] != ""){
mysqli_query($this->conexao,"INSERT INTO tabela VALUES(null,'".$tamanho[$i]."','".$estoque[$i]."','".$encomenda[$i]."');");
}
}
.....
}
POST UPDATED
I changed the following line:
novoCampo.find("[type=checkbox]").val("Sim");
I was able to get the values, but when playing in the database, according to the image above, it returns me as follows:
In other words, the IDEstoques 6 had to receive the value Yes and not the IDEstoques 5