Form does not do the action

Asked

Viewed 567 times

2

I created a form where I want to enter data in the database, but I don’t 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 of 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>
  • 3

    Change the button: type="submit". Another tip, fields you want to assign data but do not want them to be visible or editable, it is interesting you use them as hidden, as in the case of this id_professional name input. If you don’t want it to be visible, but want to be able to capture its value, you don’t need css, just change type="hidden"

1 answer

1

As @Diegofelipe said, when you want to take the value of a field, you don’t need to use the Display:none, just change the field type to hidden that it will not be displayed to the user. It would look more or less like this a field:

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

And for your form to be submitted, simply change the type of the button to submit, being like this:

<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>

Browser other questions tagged

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