472,958 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 2981
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.