Forum Moderators: coopster

Message Too Old, No Replies

Need Help displaying Form Input

TextArea

         

Gian04

2:47 am on Jun 7, 2007 (gmt 0)

10+ Year Member



I have a textarea in a form that accept input from users. Those who are requesting banner exchange will use the same form.

I have an admin page where I can view submitted inputs from users. My problem is user can input things like this:

<a href="http://www.example.com"><img src="http://www.example.com/banner.gif"></a>

When I view it on my admin page, it display the actual banner, and NOT the code as shown above.

How can I make it display just the code and not the actual banner?

[edited by: eelixduppy at 2:51 am (utc) on June 7, 2007]
[edit reason] use example.com instead [/edit]

eelixduppy

2:54 am on Jun 7, 2007 (gmt 0)



You are going to need to change the string into its entities before echoing to the browser. Use htmlentities [php.net] for this.

[edited by: eelixduppy at 11:57 am (utc) on June 7, 2007]

Gian04

2:58 am on Jun 7, 2007 (gmt 0)

10+ Year Member



I dont know how to do it, can you give a little example, given the HTML Code above. I mean I know HTML entities but I dont know how to implement in this case (given that I cant predict the user input). Thanks

[edited by: Gian04 at 3:00 am (utc) on June 7, 2007]

eelixduppy

3:01 am on Jun 7, 2007 (gmt 0)




$html = '<a href="http://www.example.com"><img src="http://www.example.com/banner.gif"></a>';
echo $html; #without entities
echo htmlentities($html); #with entities

>> given that I cant predict the user input

The user input is wherever you are storing the code. I'm assuming you are storing the code somewhere?

Gian04

3:09 am on Jun 7, 2007 (gmt 0)

10+ Year Member



Thank you very much eelixduppy it works.

My next problem is, even if there are 3 paragraphs (because the user press ENTER) it displays in a continuous manner (1 paragraph)

eelixduppy

3:12 am on Jun 7, 2007 (gmt 0)



This is overcome by using nl2br [php.net] on the string. So something like this:

echo htmlentities(nl2br($html));

Gian04

3:18 am on Jun 7, 2007 (gmt 0)

10+ Year Member



Thank you very much eelixduppy it works.

But it should be
echo nl2br(htmlentities($html));

because
echo htmlentities(nl2br($html));

will just display the '<BR>'

eelixduppy

3:19 am on Jun 7, 2007 (gmt 0)



>> will just display the '<BR>'

I thought that is what you wanted, but I guess not ;)

glad you got it working!