I am creating a multi-step form and need to ”upload”/save some information into a database. It consists of 3 forms. The problem is that only the last form is sending the information and that’s also where the submit button is.
Code sample below:
<form action=""> <div class="form-group"> <label for="">Nome Completo</label> <input type="text" name="" placeholder="Nome e sobrenome" id="" class="form-control" /> </div> <div class="form-group"> <label for="">E-mail</label> <input type="email" name="" placeholder="E-mail para contato" id="" class="form-control" /> </div> <div class="form-group"> <label for="">CPF</label> <input type="text" name="ccpf" placeholder="Ex: 000.000.000-00" id="" class="form-control" /> </div> <div class="form-group"> <label for="">Data de Nascimento</label> <input type="text" name="" placeholder="Ex: 01-12-1999 " id="" class="form-control" /> </div> <div class="form-group"> <label for="">Endereço</label> <input type="text" name="" placeholder="Ex: Av. Paulista, 99 - São Paulo - SP - 99999-99 " id="" class="form-control" /> </div> <div class="form-group"> <label for="">Telefone</label> <input type="text" name="" placeholder="Número para eventuais contatos. Ex: (99)99999-9999" id="" class="form-control" /> </div> <div class="form-group"> <label for="">Gênero</label> <select class="custom-select myinput" name="class" id="class"> <option value="male">Homem</option> <option value="female">Mulher</option> <option value="other">Outros</option> </select> </div> <div class="button-row"> <input type="button" value="Próximo" class="next" /> </div> </form> </div> <div class="form-box"> <ul class="active-button"> <li class="active"> <span class="round-btn">1</span> </li> <li class="active"> <span class="round-btn">2</span> </li> <li> <span class="round-btn">3</span> </li> </ul> <h4>Educação e Formação Acadêmica</h4> <form action=""> <div class="form-group"> <label for="">Instituições Frequentadas | Diploma | Data de Conclusão</label> <input type="text" name="" placeholder="Instituição 1" id="" class="form-control" /> <input type="text" name="" placeholder="Instituição 2" id="" class="form-control" /> <input type="text" name="" placeholder="Instituição 3" id="" class="form-control" /> </div> <div class="form-group"> <label for="">Habilidades e Qualificações</label> <input type="text" name="" placeholder="Ex: Excel Avançado, PowerBI, Python.. (SEPARE POR ',')" id="" class="form-control" /> </div> <div class="form-group"> <label for="">Idiomas</label> <input type="text" name="cidiomas" placeholder="Ex: PT NATIVO, EN C2, FR A1.. (SEPARE POR ',')" id="" class="form-control" /> </div> <div class="button-row"> <input type="button" value="Anterior" class="previous" /> <input type="button" value="Próximo" class="next" /> </div> </form> </div> <div class="form-box"> <ul class="active-button"> <li class="active"> <span class="round-btn">1</span> </li> <li class="active"> <span class="round-btn">2</span> </li> <li class="active"> <span class="round-btn">3</span> </li> </ul> <h4>Experiência de trabalho</h4> <form action="./edit_info.php" method="POST"> <div class="form-group"> <label for="">Última Experiência</label> <input type="text" name="cempregador1" placeholder="Empregador" id="" class="form-control" /> <input type="text" name="" placeholder="Data de entrada e saida. Ex: 12/2018 - 06/2020" id="" class="form-control" /><input type="text" name="" placeholder="Cargo e Responsabilidades" id="" class="form-control" /><input type="text" name="" placeholder="Salário" id="" class="form-control" /><input type="text" name="" placeholder="Motivo de Saída" id="" class="form-control" /> </div> <div class="form-group"> <label for="">Penúltima Experiência</label> <input type="text" name="" placeholder="Empregador" id="" class="form-control" /> <input type="text" name="" placeholder="Data de entrada e saida. Ex: 12/2018 - 06/2020" id="" class="form-control" /><input type="text" name="" placeholder="Cargo e Responsabilidades" id="" class="form-control" /><input type="text" name="" placeholder="Salário" id="" class="form-control" /><input type="text" name="" placeholder="Motivo de Saída" id="" class="form-control" /> </div> <div class="form-group"> <label for="">Antepenúltima Experiência</label> <input type="text" name="" placeholder="Empregador" id="" class="form-control" /> <input type="text" name="" placeholder="Data de entrada e saida. Ex: 12/2018 - 06/2020" id="" class="form-control" /><input type="text" name="" placeholder="Cargo e Responsabilidades" id="" class="form-control" /><input type="text" name="" placeholder="Salário" id="" class="form-control" /><input type="text" name="" placeholder="Motivo de Saída" id="" class="form-control" /> </div> <div class="button-row"> <input type="button" value="Anterior" class="previous" /> <input type="submit" value="Finalizar" class="submit" name="editar" /> </div> </form>
As I said, only the last form is sending the data to another php file in the same root folder (./edit_info.php), to be saved in the database:
<?php include('../config.php'); if (isset($_POST["editar"])) { $cpf = mysqli_real_escape_string($conn, $_POST["ccpf"]); $idiomas = mysqli_real_escape_string($conn, $_POST["cidiomas"]); $empregador1 = mysqli_real_escape_string($conn, $_POST["cempregador1"]); $query = "UPDATE usuarios SET cpf='$cpf', idiomas='$idiomas', empregador1='$empregador1' WHERE ID = 5"; if (mysqli_query($conn, $query)) { header('Location: ../../login/painel.php'); "<script type='text/javascript'>alert('Usuario cadastrado com sucesso!');</script>"; exit(); } else { echo "<script type='text/javascript'>alert('Falha ao cadastrar usuario. Tente novamente.');history.go(-1);</script>"; } }
That said, only $empregador1 = mysqli_real_escape_string($conn, $_POST[“cempregador1”]); is receiving the data.
Any help will be welcome!
Advertisement
Answer
Make a button and use jQuery for button click, from there you can bundle all the data from those forms using serialize() function in to single json array if data is to be submitted to one place.
or simply just create one form from those three