Questions to send data via POST

1
Hello, I'm trying to send via $ _POST some data for validation and subsequent insertion into the database, which I could do in another project the exact way I'm trying to do it now, but I'm not getting it.

This is the code for my Form:

<div class="container-fluid">
<div class="panel panel-primary">
    <div class="panel-heading">
        CADASTRAR USUÁRIO
    </div><br>

    <div id="filtros" style="padding-left: 20px">
        <a id="voltar_pagina" href="menu.php" class="btn btn-primary" title="Voltar ao início">
            <span class="glyphicon glyphicon-home"></span>
        </a>
        <a id="voltar_lista" href="javascript:history.back()" class="btn btn-primary" title="Voltar">
            <span class="glyphicon glyphicon-chevron-left"></span>
        </a>                        
    </div>

    <div class="panel-body">

        <form id="form_cad_usuario" data-toggle="validator" class="form-horizontal" method="POST" action="../config/usuario/processa_cad_usuario.php">

            <!--DADOS DO USUÁRIO-->
            <div class="page-header">
                <h4>Dados do Usuário</h4s>
                <hr>
            </div>


            <div class="form-group">                 
                <label for="ativo" class="col-sm-2 control-label">Ativo</label>
                <div class="col-sm-10">
                    <div class="checkbox">
                        <label>
                            <input id="ativo" type="checkbox">
                        </label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label for="nome_usuario" class="col-sm-2 control-label">Nome</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="nome_usuario" placeholder="Nome" data-error="Por favor, informe o nome completo para o usuário." required>
                    <div class="help-block with-errors"></div>
                </div>
            </div>

            <!--DADOS DE ACESSO-->
            <div class="page-header">
                <h4>Dados de Acesso</h4>
                <hr>
            </div>

            <div class="form-group">
                <label for="login_usuario" class="col-sm-2 control-label">Usuário</label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="login_usuario" placeholder="Usuário" data-error="Por favor, digite um nome para o usuário." required>
                    <div class="help-block with-errors"></div>
                </div>
            </div>

            <div class="form-group">
                <label for="senha_usuario" class="col-sm-2 control-label">Senha</label>
                <div class="col-sm-10">
                    <input type="password" class="form-control" id="senha_usuario" placeholder="Senha" data-error="Por favor, digite um senha para o usuário." required>
                    <div class="help-block with-errors"></div>
                </div>
            </div>

            <!--DADOS DA  REGIONAL-->
            <div class="page-header">
                <h4>Regionais Permitidas</h4>
                <hr>
            </div>

            <?php
            $resultado = lista_regionais();

            while ($registro = mysqli_fetch_assoc($resultado)) 
            {
                $id_regional = $registro['id'];
                $nome_regional = $registro['nome'];

            ?>

            <div class="col-sm-2">
                <div class="form-group">
                    <div class="col-sm-1">
                        <div class="checkbox">
                            <label>
                                <label class="col-md-10" for="<?php echo"regional_$id_regional" ?>">
                                    <input type="checkbox" name="<?php echo"regionais[$id_regional]"; ?>" id="<?php echo"regional_$id_regional" ?>"> 
                                    <small><?php echo $nome_regional; ?></small>
                                </label>
                            </label>
                        </div>
                    </div>
                </div>
            </div>

            <?php
            }
            ?>

            <div class="form-group">
                <div class="col-sm-offset-2 col-sm-10">
                    <button id="botao_salvar" type="submit" class="btn btn-primary pull-right">Salvar <span class="glyphicon glyphicon-floppy-save"></span></button>
                </div>
            </div>

        </form>
    </div>
</div>

Here is the script 'processa_cad_user.php':

<?php
session_start();

include_once ('../../dao/usuario_dao.php');

$_SESSION['cadastro_inserido'] = null;

var_dump($_POST['nome_usuario']);

//cadastra_usuario($nome, $login, $senha, $permissao, $flag_ativo, $criado, $modificado);

When I try to access, for example $ _ POST ['user_name'] php tells me that such index is not defined and by doing var_dump () returns me Null. Any suggestions?

Additionally I would like to remedy an extra doubt. At the end of the form I have some checkboxes with names of cities that are generated dynamically and I would like to know how to pass all that are selected to the page that processes the register and how should I insert them into the database and which structure use. This keeping in mind that at some point I will need them to give the user permission to access data from the cities for which he has permission. Thank you immensely to anyone who can help. Hugs to all.

    
asked by anonymous 08.07.2016 / 01:00

2 answers

1

In the inputs inside the form instead of putting "id" put "name". For example:

 <input type="text" class="form-control" name="login_usuario" placeholder="Usuário" data-error="Por favor, digite um nome para o usuário." required>
    
08.07.2016 / 02:37
0

Just add the "name" attribute to your inputs with the same ID value:

<input type="text" class="form-control" id="nome_usuario" name="nome_usuario" ... >

The id in this case is used to bind the field with the label and maybe for javascript validations, but it is not sent to the server. The correct thing is always to use the "name" attribute to get data on the server with POST.

    
08.07.2016 / 21:58