Form details

Asked

Viewed 109 times

0

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

I don’t 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 attribute method in form? How to send the informed data to a specific address?

  • 2

    You need to understand the minimum php... In your form you have a method and a action , then where to point the action vc captures value by variables $_POST['name_do_campo'] ou $_GET['name_do_campo'] depending on the method you use... http://php.net/manual/en/reserved.variables.post.php Consider making a [tour] and edit your question to receive a reply and avoid closing it,,,

  • Take a look here :https://answall.com/help/mcve put your html code...

  • What you want is to send the form data to an email?

  • Exactly! That’s exactly what I need.

  • Leonardo, now seeing the final comments, send to the email already a little more advanced, but not much, the fact is that in this way seems to me to be skipping steps, here the staff likes to help, but I believe that did not understand the operation of the site right, the way your question becomes wide and possibly will be closed... Understand how a constructive criticism, do not skip steps, here you will get answers to all your questions, as long as your question is within the mold ... Read [help] calmly, and divide your problems into small parts... Good Luck !

3 answers

0

To receive the data in the form, the basic is like this:

Tag form you have 2 relevant attributes in this scenario. o method and the action.

By default in the absence of action it will return the action on the same page, in case your form is saved on a page .html, you will not be able to receive the data by php on the same page, making it necessary to define a action which will point 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, the name. It identifies the field name.

<input name="dado_nome"/>

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

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

receive_data.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 short, that’s it...

  • Thank you! I will try. I even looked in W3 Schools, yahoo Answers and everything else. My biggest problem is not to declare inputs... Every time I click send in my offline html, it opens the page .php. I will use a free Webhost to see if I can put into practice, part by part and so refine what needs to be refined! Thanks for the help!

  • After receiving the form data, to send an email... This email has to be one of the same Webhost or it can be anyone?

  • We’re here for this... To do these tests if all you need to do is set up an Apache... Then you can send it up with gmail... After you take the tests, consider evaluating my response... G ;)

0

Note that each input has been given one 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 recover the data passed on form see that I gave a name for each input and your submit (button) see the 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";
 }
}
?>

-1

You can use in 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 guess that’s it, I hope I helped.

  • So I could send it to a specific email address? Or just store it in a database, @Nathan Macedo?

  • Look your example has a number of mistakes, consider reviewing it not to be negative.

  • @Leonardomatiazzo this example is just a basic excerpt that you will need to make adjustments to your need. In case you want to make a connection to a database or even send via email. I find it interesting that you look in the PHP documentation how you make the connection to the database of your preference PDO and in case you want to send by email using the php mail function or an existing and well-known class like Phpmailer. The following are some links: -http://php.net/manual/en/function.mail.php -https://www.w3schools.com/php/php_mysql_connect.asp

  • @Magichat Consider introducing me to the bug so I can learn too !

  • Did you test your code? Or did you just write it and think, "That’s correct! I’ll post." ?

  • @Magichat actually I just wanted to give the guidelines to him regarding his doubt. Not only enter the code for it. But if I took that code I would probably make it work by putting only a Submit button and putting the default html structure in the html example.

  • Face don’t take this the wrong way, I ask this way the times it is for the person to reflect, I don’t know if it is correct, idem of the input, and you put echo in the variable with simple quotes... They are a series of errors that I just noticed and as you through my questioning wanted to give you guidelines for you to review your code, but not even you considered... Take it as a constructive criticism...

  • Yes, thank you .

Show 3 more comments

Browser other questions tagged

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