Form Data

1

I have a form already formatted in CSS and HTML. How do I receive the data entered on the form after filling in?

I do not understand much about PHP.

<form class="w3-container" id="contato">
  <p>
  <label><b>Nome</b></label>
  <input class="w3-input w3-animate-input" type="text" id="nome"></p>
  <p>
  <label><b>Sobrenome</b></label>
  <input class="w3-input w3-animate-input" type="text" id="empresa"></p>
  <p>
  <label><b>E-mail</b></label>
  <input class="w3-input w3-animate-input" type="text" id="email"></p>
  <p>
  <label><b>Telefone</b></label>
  <input class="w3-input w3-animate-input" type="text" id="telefone"</p>
  <p>
  <input type="submit" class="w3-btn w3-center w3-gray" style="margin-left:270px">
</form>

I use the method attribute in form ? How to send the data to a specific address?

    
asked by anonymous 23.05.2017 / 15:03

3 answers

1

To receive the data in the form, the basic is as follows:

In the form tag you have 2 relevant attributes in this scenario. the method and the action .

By default in the absence of action it will return the action on the same page, if your form is saved on a .html page, you will not be able to receive data by php on the same page, making it necessary set a action that points to the page that will receive this data, .ex:

<form action="recebe_dodos.php">

The other attribute method , specifies the request method, which by default is $_GET .

<form method="GET" action="recebe_dados.php">

There is a third relevant attribute, name . It identifies the field name.

<input name="dado_nome"/>

The value of this name is what will be used to receive the data, eg:

<form class="w3-container" id="contato" method="GET" action="recebe_dados.php">
  <p>
      <label><b>Nome</b></label>
      <input class="w3-input w3-animate-input" type="text" id="nome" name="dado_nome"/>
      <input type="submit" class="w3-btn w3-center w3-gray" style="margin-left:270px"/>

  </p>
</form>

recib_dados.php

<?php
$nome = $_GET['dado_nome'];//pegando o valor do input com o name 'dado_nome' e atribuindo a variável $nome;
echo $nome;// A saída é nome digitado.
?>

In summary is this ...

    
23.05.2017 / 16:12
0

Notice that each input was given a name , I modified your code

<form class="w3-container" id="contato" method="post">
  <p>
  <label><b>Nome</b></label>
  <input class="w3-input w3-animate-input" type="text" id="nome" name="nome"></p>
  <p>
  <label><b>Sobrenome</b></label>
  <input class="w3-input w3-animate-input" type="text" id="empresa" name="empresa"></p>
  <p>
  <label><b>E-mail</b></label>
  <input class="w3-input w3-animate-input" type="text" id="email" name="email"></p>
  <p>
  <label><b>Telefone</b></label>
  <input class="w3-input w3-animate-input" type="text" id="telefone"></p>
  <p>
  <input type="submit" class="w3-btn w3-center w3-gray" name="btn-form" style="margin-left:270px">
</form>

Now let's retrieve the data passed in the form check that I gave a name to each input and to its submit (button) see example:

<?php
//Se existir o clicki no botão
if (isset($_POST['btn-form'])) {
 //Váriavel nome recebe input POST nome
 $nome = $_POST['nome'];

 //Validando o formulário
 if (empty($nome)) {
   echo "Preencha seu nome";
 }
}
?>
    
23.05.2017 / 16:38
-1

You can use php $_GET['nomedoinputnamehtml']; if your form method is GET or $_POST['nomedoinputnamehtml']; if your form method is POST.

HTML example:

<form method="POST" action="meuphp.php"> <input name="email"> </form>

Example meuphp.php:

<?php $email = $_POST['email']; echo $email; ?>

I think that's it, I hope I've helped.

    
23.05.2017 / 15:11