Use the pre Within a PHP TAG of a value html

0

Good evening guys.

One more trick that I'm in doubt on my system. I've done everything at the beginning of the page with PHP to search my database. But there's a field I'm bringing through the mysqli_fetch_array that I need to bring in the original formatting that was typed in a textarea of a form.

At the time of bringing I created this line in my HTML (But went wrong):

<input type="text" id="texto-os" style="height: 150px;" name="texto_os" class="form-control" placeholder="Descreva o Serviço" value="<?php echo '<pre>'.$dados_os['ordem_servico'].'</pre>'?>

The result of this looks like this: (All in one line (even though it was written with line breaks, and showing the tag as if it had not been running them.)

  

<pre>Texto que vem do Banco de Dados</pre>

I even switched to <input type="text> "because when I was in <textarea> it did not show my contents of the Database."

Finally, in other code I use the tag after the echo to bring the original formatting, but this usually I did at once in the file only with PHP.

This time for convenience, I'm bringing field to field answers to fill out my form since I have not yet managed to do this via Javascript.

I'm doing wrong or really can not use the pre within the html value tag?

Hugs

    
asked by anonymous 22.09.2017 / 01:56

2 answers

1

The <input type="text"> only accepts one line, and you can not add HTML inside value:

<input type="text" value="<pre>olá

Mundo</pre>">

And <br> will not work either:

<input type="text" value="olá<br>Mundo">

This is not how HTML works.

What you should do is to change input=text to textarea , like this:

<textarea rows="10" cols="30">olá

Mundo</textarea>
    
22.09.2017 / 02:56
-1

To get the result of the bank with line break use the function nl2br .

In your case it looks like this:

<input type="text" id="texto-os" style="height: 150px;" name="texto_os" class="form-control" placeholder="Descreva o Serviço" value="<?php echo strip_tags(nl2br($dados_os['ordem_servico']))?> 
    
22.09.2017 / 02:28