Send values from a <H5> tag to a variable in PHP

Asked

Viewed 129 times

0

Good afternoon, you guys,

I have some information in a code that is being displayed with the tag inside an Echo, below these, I have a field for free writing, I need to send all these attributes mentioned in tags plus the text that will be typed on to another PHP page that will insert the information in the database, but I don’t know how to get this information with PHP. If you can shed some light, I’d appreciate it!

Follows the script

      try {
      $veiculo->buscar($placa);
      if ($veiculo->existe()) {
         //print_r($veiculo->dados());   
      echo "<div class='row'>
            <div class='span12' style='text-align:center; margin: 0 auto;'>
            <div class='form-group'>";
        echo "<h5>Placa: " . $veiculo->placa."</h5>";
        echo "<h5>Marca/Modelo: " .$veiculo->marca."</h5>";
        echo "<h5>Cor: " .$veiculo->cor."<h5>";
        echo "<h5>Ano: " .$veiculo->ano."</h5>";           
        echo "<h5>Chassi: " .$veiculo->chassi."</h5>";
        echo "<h5>Situação: " .$veiculo->situacao. "</h5>";
        echo "<h5>Estado: " .$veiculo->uf. "</h5>";
        echo "<h5>Município: " .$veiculo->municipio. "</h5>";
        echo "<h5>Mensagem:</h5>";
        echo "<textarea class='form-control' rows='5' id='comment'></textarea>";
      echo "</div>";                  
      echo"<a href='salvaComment.php' class='btn btn-info' role='button'>Enviar Comentário</a>";
      echo"<a href='index.php' class='btn btn-info' role='button'>Pesquise outra placa!</a>";
      echo "</div>";
      echo "</div>";
      echo "</br>";
      echo "<h6 align='center'>Data e hora da pesquisa: ".$veiculo->data."</h6>";
      }
  }catch (\Exception $e) {
    echo "<div class='row'>";
    echo "<div class='span12' style='text-align:center; margin: 0 auto;'>";
    echo "<h5>".$e->getMessage()."</h5>";
    echo "</br>";
    echo"<a href='index.php' class='btn btn-info' role='button'>Tente novamente!</a>";
  }

2 answers

0

You need to place the textarea inside a form and place a name attribute in the textarea, example name="mensagem". To get the information you should use for example $_POST['mensagem'].

  • Yes, as for the textarea I can catch it in PHP making the form, as you mentioned, but I also need the values within each <H5> tag (plate, brand, color, etc...), because in the database, the comments will be assigned according to the car data...

  • I get it, probably what you need is just the license plate, because I imagine it’s your primary key on the table with the vehicle information. You can put an Hidden input with the name attribute on the board. So to save the comment, vc gives a Select in the table by the board and adds the content of the comment.

  • In fact these data are not yet in the database, as they are searched in an external link, the function that queries in the link creates the class vehicles based on the data that are in the Host, only after being informed the comment that will be inserted in the database, That’s why I wanted to take the H5.

  • 1

    Do something similar to: <form action="salvaComment.php" method="post"> <input type="Hidden" name="plate" value="$vehicle->board"> Continue to other data like above </form> In the q file you will receive the data put: <? php echo "board" . $_POST["board"]; ?>

  • I understood, show the information inside a form even, in this way I had already done. However, as this information will only be for display, I had opted for the H5 tag more for the visual and I would like to know if it was possible to capture these values. However, I will go through the form itself, then I get the visual result I want via CSS. Thank you!

0


The information inside the H5 you already have it because it comes from the bank and Voce uses the $vehicle, just take the plate and consult the bank to get this information.

But if Voce intends to show this information to the user and let them edit them to be saved in the database, you need to put them in:

     <input type="text" name="cor" value="<?php echo $veiculo->cor;?>">
  • I still do not have this information in the database, as mentioned below, I search this data in an external link, need to add a comment to only then save in the database.

  • So as it has been said, Oce needs to put this information in input text and the comment in a textarea, da para vc pegar as informações de dentro do <H5> com javascript mas em seu caso seria melhor montar um formulario e depois que o usuario digitar tudo que precisa enviar

Browser other questions tagged

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