I need to mount an array of a form in PHP that is dynamically generated with jquery and pass this data to the DB, I am not able to separate the forms to register in the DB.
Follow the HTML:
<form id="boletin_cad" action="env_boletin.php" method="POST">
<aside id="inner_form">
<select name="aluno[]" class="selec_aluno">
<option value="">Selecione o aluno</option>
<?php
$pega_alunos = $db->prepare("SELECT * FROM efcol_cadastro WHERE status_conta = ? ORDER BY nome");
$pega_alunos->execute(array('Ativo'));
while ($dados_alunos = $pega_alunos->fetch()) {
echo '<option value="' . $dados_alunos['nome'] . '">' . $dados_alunos['nome'] . '</option>';
}
?>
</select><br />
<select name="prof[]" class="selec_aluno">
<?php
session_start();
echo '<option value="' . $_SESSION['usuario'] . '">' . $_SESSION['nome'] . '</option>';
?>
</select><br />
<select name="materia[]" class="selec_materia">
<option value="">Selecione a Matéria</option>
<option value="01">LIBERTAÇÃO I</option>
<option value="02">REGIÕES DE CATIVEIRO</option>
<option value="03">H. ESPIRITUAL</option>
<option value="04">ESQ. JEZABEL</option>
<option value="05">ABORTO</option>
<option value="06">ADULTÉRIO</option>
<option value="07">DIVÓRCIO</option>
<option value="08">LIB. SEXUAL I</option>
<option value="09">LIB. SEXUAL II</option>
<option value="10">INIMIGOS ESPIRITUAIS</option>
</select><br />
<legend>
<span>Ano Letivo</span>
<input type="text" name="ano[]" class="input_ano" />
</legend>
<legend>
<span>Semestre</span>
<select name="semestre[]" class="selec_semestre">
<option value="1">1º</option>
<option value="2">2º</option>
</select></legend><br /><br />
<legend>
<span>Média</span>
<input type="text" name="media[]" class="input_notas"/>
</legend>
<legend>
<span>Faltas</span>
<input type="text" name="faltas[]" class="input_faltas"/>
</legend><br /><br />
<div class="progress">
<div class="bar"></div >
<div class="percent">0%</div >
</div>
<div id="status"></div>
</aside>
<div class="botoes">
<button name="add_media">Cadastrar</button>
<a href="javascript:void(0);" class="add_aluno">+ ADD ALUNO +</a>
<!--<a href="javascript:void(0);" class="teste">+ TESTE +</a>-->
</div>
</form>
And Jquery:
$("body").on('click', 'button[name="add_media"]', function () {
var bar = $('#boletin_cad .bar');
var percent = $('#boletin_cad .percent');
var status = $('#boletin_cad #status');
$('#boletin_cad').ajaxForm({
beforeSend: function () {
status.empty();
var percentVal = '0%';
bar.width(percentVal);
percent.html(percentVal);
},
uploadProgress: function (event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.width(percentVal);
percent.html(percentVal);
status.html('Processando aguarde...');
},
success: function () {
var percentVal = '100%';
bar.width(percentVal);
percent.html(percentVal);
},
complete: function (xhr) {
status.html(xhr.responseText);
},
datatype: 'json',
url: 'env_boletin.php',
resetForm: false
});
});
This is the file I'm looking for the array to save to BD:
$nome = $_POST['aluno'];
$professor = $_POST['prof'];
$materia = $_POST['materia'];
$ano = $_POST['ano'];
$semestre = $_POST['semestre'];
$media = $_POST['media'];
$faltas = $_POST['faltas'];
$arr = array(
'nome' => $nome,
'professor' => $professor,
'materia' => $materia,
'ano' => $ano,
'semestre' => $semestre,
'media' => $media,
'faltas' => $faltas
);
In this case, I would like to create an array that would separate form 1 from form2 ... and save it from DB already thanks.