Store form data in array without database

Asked

Viewed 42 times

1

How to store form data in an array with the $_SESSION variable in PHP, without database?

<form class="needs-validation formulario" novalidate="" action="" method="POST">
                        <input type="hidden" name="time" value="1611249498">


                        <div class="row lista_dependente">
                            <div class="col-md-12 mb-3  remove_dependente_1">
                                <label for="nomeCompleto" class="label">Nome completo <span class="text-muted">*</span></label>
                                <div class="input-group input-group-lg">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text"><i class="fa fa-user"></i></span>
                                    </div>
                                    <input type="text" class="form-control" id="nomeCompleto" name="dependente[nomeCompleto]" placeholder="Nome completo" required="">
                                    <div class="invalid-feedback" style="width: 100%;">Campo obrigatório.</div>

                                </div>

                            </div>
                            <div class="col-md-6 mb-3 remove_dependente_1">
                                <label for="nascimento" class="label">Data de nascimento  <span class="text-muted">*</span></label>                                    
                                <div class="input-group input-group-lg">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text"><i class="fa fa-calendar"></i></span>
                                    </div>
                                    <input type="date" class="form-control nascimento" id="nascimento" name="dependente[nascimento]" placeholder="Data de Nascimento" required="">
                                    <div class="invalid-feedback" style="width: 100%;">Informe a data de nascimento.</div>

                                </div>

                            </div>
                            <div class="col-md-6 mb-3 remove_dependente_1">
                                <label for="sexo" class="label">Sexo  <span class="text-muted">*</span></label>
                                <div class="row"> 
                                    <ul class="ul-radio">
                                        <li class="left">
                                            <label for="sexo"> <input id="sexo" name="dependente[sexo]" type="radio" class="form-control" value="Masculino">Masculino</label>
                                        </li>
                                        <li class="right"><label for="sexoF"> <input id="sexoF" name="dependente[sexo]" type="radio" class="form-control" value="Feminino">Feminino</label>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <div class="col-md-12 mb-3 remove_dependente_1">
                                <a href="#" class="btn btn-danger btn-sm btn-block" onclick="num_dependente(1);return false">Remover dependente</a>
                            </div>
                        </div>

                        <div class="clearfix"></div>
                        <hr class="mb-4 btn-dependente" style="">
                        <div class="clearfix"></div>

                        <button class="btn btn-info btn-lg btn-block btn-click btn-dependente" style="" type="submit"><i class="fa fa-send"></i> Cadastrar dependente</button>

                        <div class="clearfix"></div>
                        <hr class="mb-4 btn-dependente" style="">
                        <div class="clearfix"></div>

                        <div class="row" style="display:none;">
                            <div class="form-group col-md-12">
                                <label><input class="checkbox" type="checkbox" name="autoriza" value="1"> Autorizo a utilização dos meus dados no cadastro</label>
                            </div>
                        </div>
                        <button class="btn btn-success btn-lg btn-block btn-click" type="submit" style="display: none;"><i class="fa fa-send"></i> Concluir cadastro</button>


                    </form>

I’m doing it this way:

if (!$_SESSION['dados_paciente']) {
        $_SESSION['dados_paciente'] = array();
    }
    if (!$_SESSION['dados_responsavel']) {
        $_SESSION['dados_responsavel'] = array();
    }
    if (!$_SESSION['dados_dependente']) {
        $_SESSION['dados_dependente'] = array();
    }
    
    $_SESSION['dados_paciente'] = $_POST['paciente'];
    array_push($_SESSION['dados_paciente'], $_POST['paciente']);
    $_SESSION['dados_responsavel'] = $_POST['responsavel'];
    array_push($_SESSION['dados_responsavel'], $_POST['responsavel']);
    $_SESSION['dados_dependente'] = $_POST['dependente'];
    array_push($_SESSION['dados_dependente'], $_POST['dependente']);

    echo '<pre>';
    var_dump($_SESSION['dados_paciente'], $_SESSION['dados_responsavel'], $_SESSION['dados_dependente']);
    echo '</pre>';

I have a test link: https://pacientes.agenciaweblab.com.br/index2.php?tel=71988509593

  • What do you know about PHP? Have you ever tried to do anything? If so, what was the result?

  • I’m doing it here:

  • You must [Dit] the question and put any and all content referring to the problem in it.

  • I just edited

  • you have some contact Woss?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.