Doubt in form involving select

Asked

Viewed 25 times

0

Hello. I have a question where I need to get user information and send it to php. I’m not getting the user’s choice information. He needs to choose whether he’s a client or whether he works in options. I wanted to know if it is possible to send this information, because I have a table called position in the bank where I keep if the user is a client or employee.

Form

<form class="" method="post" action="controleUsuario.php">
        <h1 class=""><b>Cadastrar</b></h1>
        <div class="form-group"> <label for="nome">Nome:</label> <input type="text" class="form-control" name="nome" id="nome" placeholder="Digite seu nome"> </div>
        <div class="form-group"> <label for="email">Email:</label> <input type="text" class="form-control" id="email" name="email" placeholder="Digite seu Email"> </div>
        <div class="form-group"> <label for="senha">Senha:</label> <input type="password" class="form-control" id="senha" name="senha" placeholder="Digite sua senha"> </div>
        <label class="mr-sm-2 sr-only" for="escolha">Escolha:</label>
        <div class="form-row align-items-left">
        <div class="col-auto my-1">
  <select class="custom-select mr-sm-2" name="escolha" id="escolha">
    <option name="cliente" id="cliente" value="Cliente">Cliente</option>
    <option name="funcionario" id="funcionario" value="Funcionario">Funcionario</option>
  </select>
  </div>
</div>

        <button type="submit" name="opcao" value="Cadastrar" class="btn btn-primary">Comfirmar</button>
      </form>

controlUsuario

if(isset($_POST["opcao"])){

$opcao = $_POST["opcao"];
$escolha = $_POST["escolha"];

if($opcao == "Cadastrar"){
    if($escolha=="Funcionario"){
    $funcionario=$_POST["funcionario"]; 
    $nome = $_POST["nome"];
    $email = $_POST["email"];
    $senha =sha1($_POST["senha"]);
    cadastroFuncionario($nome,$email,$senha,$funcionario);
    header("Location: loginUsuario.php");
    }else if($escolha=="Cliente"){
    $cliente=$_POST["cliente"]; 
    $nome = $_POST["nome"];
    $email = $_POST["email"];
    $senha =sha1($_POST["senha"]);
    cadastroCliente($nome,$email,$senha,$cliente);
    header("Location: loginUsuario.php");   
    }

}
  • I don’t get it. $_POST["choice"] works as it should, but what are you trying to access with $_POST["run"] and $_POST["client"]? You’re not sending anything with that name, what should be in these keys?

  • You should have. If he’s working he’ll send "working" for this variable

  • Why do you need to "run" within $_POST["run"] if you already have "run" within $_POST["choose"]?

  • Man, that confused me had not understood right this $_POST deal

1 answer

0


Options are the different options a select has, expressed with the label <OPTION>

<select name="NOME" size="ALTURA">
<option value="VALOR A PASSAR">VALOR MOSTRADO</option>
<option value="VALOR A PASSAR">VALOR MOSTRADO</option>
<option value="VALOR A PASSAR" SELECTED>VALOR MOSTRADO</option>
</select>

Attributes of the option tag:

  • (value): With this attribute, we define the information that each item will send to the server if it is selected.
  • (Selected): With this attribute, we define between the inserted items, which will appear previously selected.

Name not used in options

    <select class="custom-select mr-sm-2" name="escolha" id="escolha">
      <option name="cliente" id="cliente" value="Cliente">Cliente</option>
      <option name="funcionario" id="funcionario" value="Funcionario">Funcionario</option>
    </select>

therefore, something like $funcionario=$_POST["funcionario"]; is useless

When you send the form to PHP, the script responsible for receiving the information will know exactly the form name "escolha" and will know the value that was chosen (Cliente or Funcionário).

PHP will recover the value of option marked by name select

In your case $escolha = $_POST["escolha"];

Browser other questions tagged

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