Jump to content

Formatting form data


dbillings

Recommended Posts

I have a problem understanding how I can submit form data to a mysql database and preserve the formatting that the user wants. Essentially the problem is line breaks. When a user inserts data into a text area the text automatically jumps to the next line when the one line fills up with text. Yet when the data is submitted to mysql it doesn't preserve the breaks. I've tried several solutions like the <pre> tag. Basically I want the break that the html textarea creates automatically when it reaches the end of the text area to generate a <br /> tag in my data submission. If anyone can give me a solution I would appreciate it. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/60131-formatting-form-data/
Share on other sites

asically I want the break that the html textarea creates automatically when it reaches the end of the text area

 

There is no linebreak created automatically, its just the wrapping affect of displaying data within a textarea. You could try using wordwrap when displaying this data back to fake it.

 

Another function to look into would be nl2br, this comes in handy for changing actual linebreaks into

<br />

tags.

 

Note: Both these functions should only be applied to your data on the wway out of the database. Store your data in its raw format wherever possible.

Link to comment
https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299142
Share on other sites

<pre>Hello                    This                              is                                    a                  test                  of                                  how                      this                        forum                          handles                                        a                                              pre                  tag                              </pre>

Link to comment
https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299168
Share on other sites

dbillings, basically you have 2 options (yes it always comes down to 2 options it seems)

 

1. Use a WYSIWYG type Editor and save the contents of that to your DB

2. Do as suggested, save the textarea as normal, and then when you do something like this:

 

<?php

$q = "select textarea from myTable where id='1'";
$result = mysql_query($q);
$data = mysql_fetch_array($result);

print nl2br($data['textarea']);
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/60131-formatting-form-data/#findComment-299185
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.