& to & in text fields

5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 25, 2009   (RSS)

Hi,

When entering text into a text field (text box, text field etc), when you type an AND sign (&), it renders/displays this directly in the html source as "&".

"&" results in invalid xHTML - it needs to be converted to the correct escape format of "&" in order to validate.

If I type "&" in the text field, it displays "&" on the page, rather than converting it to correct display character, e.g.

"The house & the car"


So... is there anyway the textbox/fields can be fixed so that automatically convert & to & to correctly parse it in xHTML?

Hope that makes sense...

Cheers
Rob

Re: [rjbathgate] & to & in text fields

By Kenny - March 25, 2009

Rob,

I'm not able to duplicate your problem.

Whenever I type in &amp it displays as &

I have tested this on a textbox and text field using version 1.27

Kenny

Re: [rjbathgate] & to & in text fields

By Dave - March 25, 2009

Hi Rob,

We store user input exactly as it is entered because we don't know what the output medium might be (web page, xml, email, etc). So if you enter & it will be stored (and output) as &.

You can automatically encode output as html entities with the php function htmlspecialchars(). So instead of this:
<?php echo $record['title'] ?>

You could have:
<?php echo htmlspecialchars($record['title']) ?>

For more details see: http://www.php.net/htmlspecialchars

Hope that helps, let me know if that does what you need.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] & to &amp; in text fields

Excellent :)

Will give that a play, cheers Dave!