& to & in text fields

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

By rjbathgate - March 25, 2009

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: [sagentic] & to & in text fields

By rjbathgate - March 25, 2009

Ha you're right, it works now...

Perhaps it's been fixed in an update of the CMSB... or when I was trying it, I'd done something wrong...

Note it needs to be & to validate (with the ;)

While this works, it's not ideal from userability point of view - can't expect the client to type & instead of &, so ideally it'd be good if it can still auto turn "&" into &

Cheers :)

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

By rjbathgate - March 25, 2009

Excellent :)

Will give that a play, cheers Dave!