Write textarea line break in database

Asked

Viewed 395 times

1

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

The 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 point is that if the user jumps line to organize the information, when I saved in the database "insert into flor (informacoes) values ('".$informacoes."')"; line breaks are lost...

How to save data from textarea with the line breaks?

1 answer

1


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

Browser other questions tagged

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