Write textarea line break in database

1

I have <textarea class="form-control" id="informacoes" name="informacoes" rows="3" placeholder="descreva aqui..."></textarea> where the user can enter various information.

Information is sent via ajax :

function salvaFlor(){
  var myForm = document.getElementById('formflor');
  var form = new FormData(myForm);

  $.ajax({
    type: "POST",
    url: "functions/salvarFlor.php",
    data: form,
    cache: false,
    contentType: false,
    processData: false,
    success: function(data) {
      if (data == 'ok'){
        alert('Dados salvos com sucesso!');
        listaFlor();
      }else{
        alert(data);
      }
    }
  });
}

The issue is that if the user skips the line to organize the information, when I save on the "insert into flor (informacoes) values ('".$informacoes."')"; database the line breaks are lost ...

How can I save the data of textarea with line breaks?

    
asked by anonymous 23.01.2018 / 12:01

1 answer

1

You can use the nl2br function to do this. In your salvarFlor method you can do this: $textArea = nl2br($stringTextArea);

    
23.01.2018 / 12:17