473,785 Members | 2,482 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<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 3029
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>Commen t:</td><td>$value</td></tr>";

--
-bts
-Motorcycles defy gravity; cars just suck
Nov 20 '07 #2
In article <c3************ *************** *******@e1g2000 hsh.googlegroup s.com>,
Icarus - iD_Ten_T helper <ig************ **@gmail.comwro te:
>
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 'htmlspecialcha rs()'.) 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************ *************** *******@f3g2000 hsg.googlegroup s.com>,
John Dunlop <jo**@dunlop.na mewrote:
>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.comwro te:
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
4725
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 key... vbcrlf...) from the input so that somebody doesn't do something like fill the textarea with 100s of keypresses of the enter key and end up spitting out tonnes of blank pages on the fax machine
4
4328
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: http://validator.w3.org/check?uri=http://www.stargazing.net/mas/COMET.htm In the <textarea> of this page I have Javascript code. I can't figure out how to present this code and still be w3c valid. Any advice would be appreciated...Dennis
11
13725
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, there's an "Edit" link. So the page itself looks something like this: <HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY> <!-- TEXT STARTS HERE --> <H1>Hello World!</H1> <P>More stuff here...</P>
3
5678
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 replace spaces with &nbsp;. The <br> part works well enough, but I keep getting "%20" instead of "&nbsp;" for the spaces. I understand that escape() changes " " to "%20", but I would think the ConvertSpaces function below would change the %20 to...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.