Form does not do the action

2

I created a form where I want to insert data into the database, but I do not want the user to enter the data, so I put display:block in the form. However when I click the button nothing happens.

The code for form is as follows:

<form role="form" action="inserir_pedido.php" method="post">
  <input type="text" name="id_servico" id="id_servico" style="display:none;">
  <input type="text" name="nome_servico" id="nome_servico" style="display:none;">
  <input type="text" name="horas" id="horas" style="display:none;">
  <input type="text" name="id_profissional" id="id_profissional" style="display:none;" value="<?php echo $_GET['id'] ?>">
  <input type="text" name="id_utilizador" id="id_utilizador" style="display:none;">
  <button type="button" class="btn btn-info">Enviar email</button>
</form>
    
asked by anonymous 01.02.2016 / 00:45

1 answer

1

As @DiegoFelipe said, when you want to get the value of a field, you do not need to use Display:none , just change the field type to hidden that it will not be displayed to the user. It would look something like this:

<input type="hidden" name="id_servico" id="id_servico">

And for your form to be submitted, simply change the button type to submit , thus:

<button type="submit" class="btn btn-info">Enviar email</button>

The complete solution would look like this:

<form role="form" action="inserir_pedido.php" method="post">
  <input type="hidden" name="id_servico" id="id_servico">
  <input type="hidden" name="nome_servico" id="nome_servico">
  <input type="hidden" name="horas" id="horas">
  <input type="hidden" name="id_profissional" id="id_profissional" value="<?php echo $_GET['id'] ?>">
  <input type="hidden" name="id_utilizador" id="id_utilizador">
  <button type="submit" class="btn btn-info">Enviar email</button>
</form>
    
01.02.2016 / 11:54