I have a kind of a guestbook on my page. It's just a common textarea like this:

echo '
<textarea name="msg"></textarea>';

and then I use a form to send me to the backend on submit:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$jinput = JFactory::getApplication()->input;
$msg = $jinput->getString('msg');
$columns = array('message');
$values = array($db->quote($msg);
$query->insert($db->quoteName('guestbook'))->columns($db->quoteName($columns))->values(implode(',', $values));

But my problem is, that if the user write something like:


This is a nice site.

Bye for now!

The guestbook prints out:

Hey. This is a nice site. Bye for now!

How can I get the line breaks from the user-inputs?

EDIT: I echo the results like this:

$results = $db->loadObjectList();
foreach ($results as $row) {
echo $msg;
  • Does your data saved in manner which is you wanted to show ? – Sudhir Sapkal May 22 '18 at 11:42

You don't show how you are echoing the result, but have you tried wrapping it in nl2br?

  • Just edited my question :) Don't know how to wrap it but I'll take a look :) – Daniel Jensen May 23 '18 at 5:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.