Picking text from an input text

Asked

Viewed 979 times

2

I have the following form

<form method="POST">

<input id="comentario" type="text" name="comentario" id="comentario">
<input type="submit" name="Comentar" value="Comentar" id="Comentar">

</form>

And I need to display on the screen what’s typed in the input text. I also have this section that checks if the button was clicked (I intend to do my logic here)

<?php
if(isset($_POST['Comentar'])){
        echo "botão foi clicado";

    }
 ?>
  • you want to know if Submit was made by the boot? will there be more buttons? or See just want the Submit to be made by the boot?

  • What was written in <input> of the kind text(the first of the html displayed) is accessible with $_POST["comentario"]. What is the specific issue?

  • @Isac she wants to recover button value, not input... Is there a need for Submit? could do with jquery and send via $.post? could better formulate your need, your resources pq suddenly your way is not the best way...

  • Catch the value of a submit ? For what purpose ? Never changes is always the same. It seems to me an XY problem

  • I think the question title is wrong. What he wants is to recover the value of what was typed in type="text because no one I know can type anything into a Ubmit input

  • Oops, I really messed up, it’s input text. You can edit?

  • Just below the line echo "botão foi clicado"; place echo $_POST['comentario'];

  • edited for you

  • @Deyci you want to send via Ajax ? 'Cause if you’re just gonna send via POST not the need for the Javascript.

Show 4 more comments

2 answers

1

    <form action="" method="post">
     Escolha um botão
      <button name="Comentar" type="submit" value="escolha1">HTML</button>
      <button name="Comentar" type="submit" value="escolha2">CSS</button>
    </form>

Here, if you recover the value of 'Comment' you can manipulate, for example, if it is not empty, it already means that some is clicked, or you can check which was... If Submit is done with enter in an input the value will be empty.

  <?php
if(isset($_POST['Comentar'])){
        echo "um botão foi clicado";
      if($_POST['Comentar] =='escolha1'){
         echo "clicou em HTML";
       }
    }
 ?>

1


To receive the shipment via POST, you use the variable $_POST["name_do_input"]

<form method="POST">

<input id="comentario" type="text" name="comentario" id="comentario">
<input type="submit" name="Comentar" value="Comentar" id="Comentar">

</form>
<?php
if(isset($_POST['Comentar']))
{   echo "botão foi clicado"."<br/>";
    $texto_digitado = $_POST["comentario"];
    echo  "Texto digitado: ".$texto_digitado;
}
?>

Browser other questions tagged

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