Current location: Hot Scripts Forums » Programming Languages » Perl » How to preserve line breaks in TEXTAREA...question please


How to preserve line breaks in TEXTAREA...question please

Reply
  #1 (permalink)  
Old 04-19-09, 07:07 PM
serazoo serazoo is offline
New Member
 
Join Date: Jan 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
How to preserve line breaks in TEXTAREA...question please

Hello all...

please help, I've tried so many combination of scripts...I'm going bananas

I've would like my textarea to preserve all line breaks when saved into the database (.txt) file

please tell what could be the magic line to insert and where ?

cheers

Sandra



here's my script:

-------------------------------------------

sub new_items{

$form{'function'} eq "save_new_items" and &save_new_items;


# Section Heading
###########################
print qq~
<P>
<table border="0" width=98%" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="800000"><font face="Verdana, Arial, Helvetica, sans-serif" size="2" color="ffffff"><b>Add New Items</b></font></td>
</tr>

<tr>
<td bgcolor="000000"><img src="space.gif" width="1" height="2" vspace="0" hspace="0"></td>
</tr>

<tr>
<td>
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">
<ul>
&nbsp;<br>
$save_message
~;

$counter = 1;

foreach (@table_fields)
{
$size = "";
$fieldsize{$counter} and $size = qq~size="$fieldsize{$counter}"~;

!$form{$counter} and $form{'function'} ne "preview" and $form{$counter} = $default_input{$counter};

$datatype{$counter} eq "Text" and $input = qq~<input type=text name="$counter" value="$form{$counter}" $size>~;
$datatype{$counter} eq "Textarea" and $input = qq~<textarea name="$counter" cols="46" rows="20"

$fieldsize{$counter}>$form{$counter}</textarea>~;
$datatype{$counter} eq "Option" and do{

@options = split (/\n/, $optionfields{$counter});
$input = qq~<select name="$counter">\n~;

foreach $option(@options)
{
$selected = "";
$form{$counter} eq $option and $selected = "selected";

$input .= qq~<option $selected>$option</option>\n~;

}#end foreach option

$input .= qq~</select>~;

};#end option do


$datatype{$counter} eq "Checkbox" and do{

$checked = "";
$form{$counter} and $checked = "checked";
$input = qq~<input type=checkbox name="$counter" value="1"> $optionfields{$counter}~;

};#end checkbox do

print qq~
<font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="">
<b>$_:</b></font><br>
$input<P>
~;
$counter++;
}
print qq~
</ul>
</td>
</tr>
</table>
<p>
<font size="2" face="Verdana, Arial, Helvetica, sans-serif" color="">
<center>
<b>
<input type=hidden name="menu" value="new_items">
<input type=radio name="function" value="save_new_items" checked> Save Directly
<input type=radio name="function" value="preview"> Preview<P>
</b>
<input type=submit value="Send New Entry">
<P>
</center>
~;


}

###########################################
sub save_new_items
{
$error_message = "";
$new_line = "";
$counter = 1;
&load_db;


foreach (@table_fields)
{
$requiredfield{$counter} and !$form{$counter} and $error_message .= qq~<b>$_</b> is a required field, and nothing has been entered.<br>~;
$uniquefield{$counter} and !$form{$counter} and $error_message .= qq~<b>$_</b> is a unique, required field, and nothing has been entered.<br>~;

# Check Required Status
#######################################
$uniquefield{$counter} and $form{$counter} and do{

foreach $keys (keys %data_hash)
{$data_hash{$keys}{$_} eq $form{$counter} and $error_message .= qq~<b>$_</b> is required to be a unique field, and has been found in the

database at line $keys.<br>~;}

};#end required field do


# Remove New Lines
######################################
$form{$counter} =~ (s/\r\n/ /g);

# Create New Line By Adding Next Field
######################################
$new_line .= qq~$form{$counter}|~;

$counter++;
}

# Save if No Errors
######################################
!$error_message and do{
open (FILE, ">>$data_file");
print FILE qq~$new_line\n~;
close (FILE);
chmod(0666,"$data_file");

%form = ();

$save_message = qq~<b>New Record Has been Saved</b><P>~;
};# end save to file

# Report Errors if Present, Return
######################################
$error_message and do{

$save_message = qq~New Record Has <b>Not</b> been Saved. Please correct the following:<P>$error_message<P>~;

};# end save to file

}#end save new items


1;



------------------------------------------
Reply With Quote
  #2 (permalink)  
Old 04-19-09, 09:01 PM
End User's Avatar
End User End User is offline
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
Quote:
Originally Posted by serazoo View Post
Hello all...

please help, I've tried so many combination of scripts...I'm going bananas

I've would like my textarea to preserve all line breaks when saved into the database (.txt) file
Generally it's best if you don't modify the data going into the database unless it's absolutely necessary. If you must, you can replace the newlines (\n) with breaks (<br />).
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | [url=http://www.codmb.com/Call Of Duty[/url]
Reply With Quote
  #3 (permalink)  
Old 04-23-09, 07:42 AM
Facundo Facundo is offline
Wannabe Coder
 
Join Date: Apr 2009
Posts: 103
Thanks: 0
Thanked 0 Times in 0 Posts
Using str_replace()

also insert into your textarea wrap="hard" that way in the database it will show the line breaks
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving division chiragkhunti CSS 5 03-19-09 12:47 PM
No error message... stormshadow PHP 3 12-11-06 06:31 PM
Redirection back to a page from form submit DAL Perl 11 03-21-05 02:45 PM
I most definately suggest DevelopingCentral.com For Any Website Design/Development! Salty777 General Advertisements 2 10-01-04 04:27 AM
asp-iis-Server error nsuresh_rasr ASP.NET 3 02-08-04 12:47 AM


All times are GMT -5. The time now is 04:52 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.