HTML Doubt Send text from an inputtext to php

Asked

Viewed 144 times

3

Hello I’m starting in html + php I’m having trouble sending the information from a text field to my php.

follows my html code.

<html>
<head>
<title>.. Telefone ..:</title>
<h1>Lista de Telefones</h1>
<h2>Informe o Telefone:</h2>
<input type="text" name="nume" onClick="document.formulario.numerotelefone.value =nume">



<form method=post name="formulario" action="executa.php">
	<input type="hidden" name="numerotelefone" value=nume>
	<input type="submit" value="Pesquisar">
</form>
</head>
</html>

follow my php code

<?php
    $exibetelefone = $_POST['numerotelefone'];
    echo "Telefone: ".$exibetelefone."<br>";

?>

I receive the text written in number instead of the number I reported in the inputtext field could help me?

  • Why put the attribute value=nume and Javascript document.formulario.numerotelefone.value =nume?

  • Victor, to better understand your need, would you be able to explain to us why there are two inputs to the phone? In case you don’t know I suggest removing the input unnecessary and proceed as some of the answers below.

  • i cleaned hygienically the code was with 2 inputs really was using Hidden because before I was using a checkbox I found that the process was the same I am reading deeper this part is I wanted to see if my idea would work before trying hehe thanks for returning

3 answers

2

You are sending the 'numerotelefone' via the Hidden input with the nume default value, via value=nume.

If you want to enter the phone number, use this code:

<html> 
<head> 
<title>.. Telefone ..:</title> 
<h1>Lista de Telefones</h1> 
<h2>Informe o Telefone:</h2> 
<form method=post name="formulario" action="executa.php">   
    <input type="text" name="numerotelefone">   
    <input type="submit" value="Pesquisar"> 
</form> 
</head> 
</html>

You will be changing your input from Hidden (which does not appear on the page) to text, so the form will appear for you to type. And now there is set a default value with value.

  • Got it, Hegon thanks for the details in the explanation as I mentioned up there I used the logic of the other languages and assign = I found q in html would be the same process tested here worked out thanks for the support

  • 1

    Glad to have helped and good luck in your learning.

1


Victor, change your html to this:

<html>
<head>
<title>.. Telefone ..:</title>
<h1>Lista de Telefones</h1>
<h2>Informe o Telefone:</h2>
<form method=post name="formulario" action="executa.php">
    <input type="text" name="numerotelefone">
    <input type="submit" value="Pesquisar">
</form>
</head>
</html>
  • 1

    gave certinho thank you very much for the explanation I will delve more really html and php do not understand anything I tried to use the same logic of other languages just assigning= and did not work

1

Note that in the Hidden input you set "nume" as value for the field:

<input type="hidden" name="numerotelefone" value=nume>

The onClick="document.formulario.numerotelefone.value =nume" input text will always give error, because the variable nume that you are wanting to send to the field numerotelefone does not exist, so the value of the Hidden input will always be the same, ie "nume".

Although it doesn’t make much sense what you’re trying to do, you could use onkeyup instead of onclick input text, changing the way to send the value of this field to the Hidden input numerotelefone:

onkeyup="document.formulario.numerotelefone.value = this.value"

The this.value returns the value of the field itself, and the onkeyup is fired every time you press something in the field. In short, everything you type in this text field will be sent to the Hidden field that is in the form.

As you said to be beginner, my answer was to be able to explain the mistakes, but the ideal is to do as the other answers suggest.

Browser other questions tagged

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