Boa tarde a todos!
Estou com um problema, não sei como fazer para cadastrar na tabela os dados do formulário que tem campos ocultos, fixos e os adicionais inseridos e validados com javaScript. Ao tentar fazer o insert a tabela continua vazia, se alguem poder mi ajudar ou pelo menos alguma dica de como fazer o insert, esterei muito grato?
<form action="index.php" method="post" name="cadastro">
<input type="hidden" name="contrato_excursao" value="108">
<fieldset>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input11">seu nome completo</label>
<input name="contrato_nome" type="text" class="round default-width-input mirror" id="simpleinput11G" />
</p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input12">seu celular</label>
<input name="contrato_telefone" type="text" class="round default-width-input" id="simple-input12" />
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input13">seu cpf</label>
<input name="contrato_cpf" type="text" class="round default-width-input" id="simple-input13" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input13">seu RG</label>
<input name="contrato_rg" type="text" class="round default-width-input" id="contatoRG" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input13">seu nascimento</label>
<input name="contrato_nascimento" type="text" placeholder="00/00/0000" class="round default-width-input" id="contatoNascimento" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input14">seu email</label>
<input name="contrato_email" type="text" class="round default-width-input" id="simple-input14" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="dropdown-input21contrato_totaladultos">Local de Embarque</label>
<select name="contrato_localembarque" id="dropdown-input21contrato_totaladultos">
<option selected value="">Selecione</option>
<option value="Praça da Cemig - Em frente a COMETA (Contagem)">Praça da Cemig - Em frente a COMETA (Contagem)</option>
<option value="Terminal Turistico JK (Belo Horizonte)">Terminal Turistico JK (Belo Horizonte)</option>
</select>
</p>
</div>
<div style="clear:both; margin-bottom:-15px;"></div>
<div class="stripe-separator"><!-- --></div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input15">seu cep</label>
<input name="contrato_cep" type="text" class="round default-width-input" id="simple-input15" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input16">endereço</label>
<input name="contrato_endereco" type="text" class="round default-width-input" id="simple-input16" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input17">número</label>
<input name="contrato_numero" type="text" class="round default-width-input" id="simple-input17" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input18">bairro</label>
<input name="contrato_bairro" type="text" class="round default-width-input" id="simple-input18" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input19">cidade</label>
<input name="contrato_cidade" type="text" class="round default-width-input" id="simple-input19" /></p>
</div>
<div style="float:left; margin-right:10px;"> <p>
<label for="simple-input20">estado</label>
<input name="contrato_estado" type="text" class="round default-width-input" id="simple-input20" /></p>
</div>
<div class="round error-box">
DIGITE ABAIXO OS DADOS DE TODOS OS PASSAGEIROS QUE IRÃO VIAJAR, INCLUINDO OS SEUS (SE CASO ESTIVER INDO).
</div>
<input name="Button" href="javascript:void(0);" id="anc_add" type="button" class="round blue ic-add" style="border: none; cursor: pointer; padding: 0.833em; background-position: right center; padding-right: 3em; background-repeat: no-repeat; font-weight: bold; text-transform: uppercase;" value="Novo Passageiro" />
<input name="anc_add" href="javascript:void(0);" id="anc_rem" type="button" class="round blue ic-delete" style="border: none; cursor: pointer; padding: 0.833em; background-position: right center; padding-right: 3em; background-repeat: no-repeat; font-weight: bold; text-transform: uppercase;" value="Remover Último Passageiro" />
<table width="100%" id="tbl1">
<tbody>
<tr>
<td width="25%"><div style="width:270px">Informações do Passageiro 01</div></td>
<td width="25%" style="text-align:center"><input name="passageiros_nome[]" type="text" placeholder="SEU NOME COMPLETO" class="round default-width-input mirror" id="passageiros_nome" style="font-size:12px;" /></td>
<td width="25%" style="text-align:center"><input name="passageiros_nascimento[]" type="text" placeholder="SUA DATA DE NASCIMENTO" class="round default-width-input" id="passageiros_nascimento" style="font-size:12px;" /></td>
<td width="25%"><input name="passageiros_rg[]" type="text" placeholder="SEU NUMERO DO RG / CERTIDAO NASC." class="round default-width-input" id="passageiros_rg" style="font-size:12px;" /></td>
</tr>
</tbody>
</table>
Script para adicionar e remover inputs
<script>
$(document).ready(function(){
var cnt = 2;
$("#anc_add").click(function(){
$('#tbl1 tr').last().after('
<tr>
<td width="25%">
<div style="width:270px">Informações do Passageiro 0'+cnt+'</div></td>
<td width="25%" style="text-align:center">
<input name="passageiros_nome[]" type="text" placeholder="NOME COMPLETO DO PASSAGEIRO" class="round default-width-input" id="simple-input28" style="font-size:12px;" /></td>
<td width="25%" style="text-align:center">
<input name="passageiros_nascimento[]" type="text" placeholder="DATA DE NASCIMENTO" class="round default-width-input" id="simple-input" style="font-size:12px;" /></td>
<td width="25%"><input name="passageiros_rg[]" type="text" placeholder="NUMERO DO RG / CERTIDAO NASC." class="round default-width-input" id="simple-input7" style="font-size:12px;" /></td>
</tr>');
cnt++;
});
$("#anc_rem").click(function(){
if($('#tbl1 tr').size()>1){
$('#tbl1 tr:last-child').remove();
}else{
alert('E necessario pelo menos um passageiro');
}
});
});
</script>
<input name="Button" type="button" class="round blue ic-right-arrow" style="border: none; cursor: pointer; padding: 0.833em; background-position: right center; padding-right: 3em; background-repeat: no-repeat; font-weight: bold; text-transform: uppercase; float:right; background-color: #4caf50" onclick="return validaForm()" value="Gerar Contrato" />
</fieldset>
</form>
Script para validar
<script type="text/javascript">
function validaForm(){
d = document.cadastro;
//validar nome
if (d.contrato_nome.value == ""){
alert("O campo NOME deve ser preenchido!");
d.contrato_nome.style.backgroundColor="red";
d.contrato_nome.style.color="#ffffff";
d.contrato_nome.focus();
return false;
}
if (d.contrato_telefone.value == ""){
alert("O campo TELEFONE deve ser preenchido!");
d.contrato_telefone.style.backgroundColor="red";
d.contrato_telefone.style.color="#ffffff";
d.contrato_telefone.focus();
return false;
}
if (d.contrato_cpf.value == ""){
alert("O campo CPF deve ser preenchido!");
d.contrato_cpf.style.backgroundColor="red";
d.contrato_cpf.style.color="#ffffff";
d.contrato_cpf.focus();
return false;
}
if (d.contrato_cpf.value == ""){
alert("O campo CPF deve ser preenchido!");
d.contrato_cpf.style.backgroundColor="red";
d.contrato_cpf.style.color="#ffffff";
d.contrato_cpf.focus();
return false;
}
if (d.contrato_email.value == ""){
alert("O campo EMAIL deve ser preenchido!");
d.contrato_email.style.backgroundColor="red";
d.contrato_email.style.color="#ffffff";
d.contrato_email.focus();
return false;
}
//validar email(verificao de endereco eletrônico)
parte1 = d.contrato_email.value.indexOf("@");
parte3 = d.contrato_email.value.length;
if (!(parte1 >= 3 && parte3 >= 9)) {
alert ("O campo EMAIL deve ser conter um endereco eletronico!");
d.contrato_email.style.backgroundColor="red";
d.contrato_email.style.color="#ffffff";
d.contrato_email.focus();
return false;
}
if (d.contrato_endereco.value == ""){
alert("O campo Endereço deve ser preenchido!");
d.contrato_endereco.style.backgroundColor="red";
d.contrato_endereco.style.color="#ffffff";
d.contrato_endereco.focus();
return false;
}
if (d.contrato_cep.value == ""){
alert("O campo CEP deve ser preenchido!");
d.contrato_cep.style.backgroundColor="red";
d.contrato_cep.style.color="#ffffff";
d.contrato_cep.focus();
return false;
}
if (d.contrato_numero.value == ""){
alert("O campo NUMERO deve ser preenchido!");
d.contrato_numero.style.backgroundColor="red";
d.contrato_numero.style.color="#ffffff";
d.contrato_numero.focus();
return false;
}
if (d.contrato_bairro.value == ""){
alert("O campo BAIRRO deve ser preenchido!");
d.contrato_bairro.style.backgroundColor="red";
d.contrato_bairro.style.color="#ffffff";
d.contrato_bairro.focus();
return false;
}
if (d.contrato_cidade.value == ""){
alert("O campo CIDADE deve ser preenchido!");
d.contrato_cidade.style.backgroundColor="red";
d.contrato_cidade.style.color="#ffffff";
d.contrato_cidade.focus();
return false;
}
if (d.contrato_estado.value == ""){
alert("O campo ESTADO deve ser preenchido!");
d.contrato_estado.style.backgroundColor="red";
d.contrato_estado.style.color="#ffffff";
d.contrato_estado.focus();
return false;
}
if (d.contrato_totalcriancascolo.value == ""){
alert("O campo Total Crianças de Colo deve ser escolhido!");
d.contrato_totalcriancascolo.style.backgroundColor="red";
d.contrato_totalcriancascolo.style.color="#ffffff";
d.contrato_totalcriancascolo.focus();
return false;
}
if (d.contrato_totalcriancas.value == ""){
alert("O campo Total Crianças deve ser escolhido!");
d.contrato_totalcriancas.style.backgroundColor="red";
d.contrato_totalcriancas.style.color="#ffffff";
d.contrato_totalcriancas.focus();
return false;
}
if (d.contrato_totaladultos.value == ""){
alert("O campo Total Adultos deve ser escolhido!");
d.contrato_totaladultos.style.backgroundColor="red";
d.contrato_totaladultos.style.color="#ffffff";
d.contrato_totaladultos.focus();
return false;
}
if (d.contrato_pgto.value == ""){
alert("O campo Tipo de Pagamento deve ser escolhido!");
d.contrato_pgto.style.backgroundColor="red";
d.contrato_pgto.style.color="#ffffff";
d.contrato_pgto.focus();
return false;
}
divResultado = document.getElementById('cadastro');
var suma = 0;
var f = document.nue_equipo;
var valores = document.getElementsByName('passageiros_nome[]');
for (var i = 0, j = valores.length; i < j; i++)
{
if( valores[i].value == "" )
{
suma++;
alert('O campo NOME DO PASSAGEIRO deve ser preenchido!');
return false;
//aqui se supone q cambio el stilo
//f.style.border= '1px solid #d8000c';
}
}
divResultado = document.getElementById('cadastro');
var suma = 0;
var f = document.nue_equipo;
var valores = document.getElementsByName('passageiros_nascimento[]');
for (var i = 0, j = valores.length; i < j; i++)
{
if( valores[i].value == "" )
{
suma++;
alert('O campo DATA DE NASCIMENTO deve ser preenchido!');
return false;
//aqui se supone q cambio el stilo
//f.style.border= '1px solid #d8000c';
}
}
divResultado = document.getElementById('cadastro');
var suma = 0;
var f = document.nue_equipo;
var valores = document.getElementsByName('passageiros_rg[]');
for (var i = 0, j = valores.length; i < j; i++)
{
if( valores[i].value == "" )
{
suma++;
alert('O campo RG / CERTIDAO NASC. deve ser preenchido!');
return false;
//aqui se supone q cambio el stilo
//f.style.border= '1px solid #d8000c';
}
}
document.cadastro.submit();
}
function enfocus()
{
document.forms[0].contrato_nome.focus()
document.forms[0].passageiros_nome[1].value = document.forms[0].contrato_nome.value
setTimeout("enblur()", 500)
}
function enblur()
{
document.forms[0].contrato_nome.blur()
setTimeout("enfocus()", 5)
}
</script>