473,385 Members | 1,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

<textarea> input help

First of all, my apologies if this should be in a php newsgroup and
not here, but I thought this the best place to start.

I want to parse the text from a <textareaform element but when I
pass this in a POST request to the server and then output it using
PHP, all formatting is gone.

I was under the impresssion that the textbox would register any
carriage returns or line breaks and send them in the final text for
processing?

Is there any way of forcing the textarea input to send formatting data
as well?

Essentially the idea would be to turn a text box with this in:
"Hello <= carriage return
<= line break
World <= carriage return
<= line break
Foo <= carriage return
<= line break
Bar"

into
"<p>Hello</p>
<br />
<p>World</p>
<br />
<p>Foo</p>
<br />
<p>Bar</p>"

but i can't do this is the received string at the server is does not
contain any reference to those line breaks of carriage returns. I
can't HTMLify it if you will.

Many thanks for any help you can offer
Nov 20 '07 #1
5 3009
Icarus - iD_Ten_T helper wrote:
before I out the string to the page before hand I take the POST data
and put it in a variable. then i use the PHP function str_split() to
put it into an array and I don't see any html codes in the array
entries where a carriage return should be.
No messy arrays needed. The following seems to work ok, if you don't
mind extra <br>'s in the middle of a paragraph:

$value = str_replace(Chr(10), "<br>", $value);
echo "<p>$value</p>";

...though I usually display entered content in a table, two columns, with
the field at the left, and the visitor's input in the right. So the
above would be:

echo "<tr><td>Comment:</td><td>$value</td></tr>";

--
-bts
-Motorcycles defy gravity; cars just suck
Nov 20 '07 #2
In article <c3**********************************@e1g2000hsh.g ooglegroups.com>,
Icarus - iD_Ten_T helper <ig**************@gmail.comwrote:
>
I want to parse the text from a <textareaform element but when I
pass this in a POST request to the server and then output it using
PHP, all formatting is gone.

I was under the impresssion that the textbox would register any
carriage returns or line breaks and send them in the final text for
processing?
It does... The POSTed string is exactly what you see in the box, with
newlines and spaces and so on. The corresponding PHP variable (or array
element I guess) is a copy of this. As Yucca says, you're only losing
those when your beowser gets the string back and ignores them.

There is a standard PHP function 'nl2br' that you can apply to the string
before outputting it that should do exactly what you want. (You also
might want to look at 'htmlspecialchars()'.) See the String Functions
section of the manual.

If you wanted to preserve spacing as well, I think you'd have to write
your own function to convert spaces to '$nbsp;'s or something.

Cheers,
-- Pete --

--
================================================== ==========================
The address in the header is a Spam Bucket -- don't bother replying to it...
(If you do need to email, replace the account name with my true name.)
Nov 20 '07 #3
Pete:
$nbsp;
Twice in as many days. Have I missed something?

--
Jock
Nov 20 '07 #4
In article <b9**********************************@f3g2000hsg.g ooglegroups.com>,
John Dunlop <jo**@dunlop.namewrote:
>Pete:
>$nbsp;

Twice in as many days. Have I missed something?
AARGhhhh! Well, thanks for keeping check on me, anyway... (:-/)

-- Pete --

--
================================================== ==========================
The address in the header is a Spam Bucket -- don't bother replying to it...
(If you do need to email, replace the account name with my true name.)
Nov 20 '07 #5
On Tue, 20 Nov 2007 11:24:39 +0100, Icarus - iD_Ten_T helper
<ig**************@gmail.comwrote:
I want to parse the text from a <textareaform element but when I
pass this in a POST request to the server and then output it using
PHP, all formatting is gone.

I was under the impresssion that the textbox would register any
carriage returns or line breaks and send them in the final text for
processing?
Yes, it does. HTTP POST requests for textareas with existing user
agents, are done in plain text with carriage returns preserved.

Most probably you simply passed this data to the HTML output of your
PHP script without modifying it. Consequently, the CRLF appears in the
HTML source but HTML, in most places, isn't sensitive to multiple
whitespaces.
If you need to output pre-formatted data (which is exactly what you
request), then, use the PRE HTML element.

<pre>
**************************
** Pre-formatted text **
** can be put here **
**************************
</pre>
Is there any way of forcing the textarea input to send formatting data
as well?
It does.
Essentially the idea would be to turn a text box with this in:
"Hello <= carriage return
<= line break
World <= carriage return
<= line break
Foo <= carriage return
<= line break
Bar"

into
"<p>Hello</p>
<br />
<p>World</p>
<br />
<p>Foo</p>
<br />
<p>Bar</p>"
Awful non-sense non-semantic code.
The pre-formatted text I've shown above doesn't consist of paragraphs.
Moroever, you would have issues with multiple spaces.
Nov 21 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Augustus | last post by:
Hiya, I have a form with a <textarea></textarea> to receive user input. This input is then stored in a database and sent by fax... I need to be able to remove the carriage returns (enter...
4
by: Dennis Allen | last post by:
Hi. I hope someone here can help. I'm webmaster for a local astronomy club. Just went over our web site. Have validated every htm file on the site except:...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
3
by: FunkHouse9 | last post by:
I'm working on a form to collect data in a textarea which and am trying to keep returns and spaces. I have a couple of functions that I Frankensteined together to replace returns with <br> and to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.