# Form won't accept ampersand

**URL:** <https://www.ruby-forum.com/t/form-wont-accept-ampersand/84618>\
**Category:** Rails\
**Created:** [February 6, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/form-wont-accept-ampersand/84618 "2007-02-06T15:13:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [February 6, 2007, 3:13pm UTC](https://www.ruby-forum.com/t/form-wont-accept-ampersand/84618/1 "2007-02-06T15:13:53Z")

</div>

Hi guys,

My start\_form\_tag generated form will not accept a text field containing  
an ampersand.

For example, the text ‘A & B’ is trunacted to ‘A’ in the param hash.

I know ampersands have to be encoded in URLs, but I’m surprised my form  
has a problem with this. I’ve tested this in Safari and Firefox.

thanks  
Lindsay

---

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [February 6, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/form-wont-accept-ampersand/84618/2 "2007-02-06T16:55:17Z")

</div>

It turns out start\_form\_tag isn’t the issue…

I’ve traced the problem down to an observe\_field. The value being sent  
by the AJAX call is 'A ’ - the ‘&B’ isn’t sent, as one would expect. So,  
how can I escape the value to send the ‘&’ as an ‘&’? I’ve tried  
‘:method =\> post’ but that doesn’t help either.

Lindsay

---

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [February 6, 2007, 5:41pm UTC](https://www.ruby-forum.com/t/form-wont-accept-ampersand/84618/3 "2007-02-06T17:41:42Z")

</div>

I know that the function h(string) strips a string and converts all  
escape characters into their html-code equivalents.  
so:  
h “A & B”  
will return “A &amp; B”  
or  
h “A \< B”  
returns “A \< B”

I hope this helps, it’s one of the few things I know!

Sebastian Wolf

On Feb 6, 3:55 pm, Lindsay B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Lindsay\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ecae2f/32.png) [@Lindsay\_B](https://www.ruby-forum.com/u/Lindsay_B)\
**Post date:** [February 6, 2007, 5:45pm UTC](https://www.ruby-forum.com/t/form-wont-accept-ampersand/84618/4 "2007-02-06T17:45:42Z")

</div>

Hi Lindsay,

Hi Lindsay,

Lindsay B. wrote:

> how can I escape the value to send the ‘&’  
> as an ‘&’?

The problem, in general terms, is about accepting non-text input from  
users.  
It’s dangerous. Here’s a link to get you started.

> **[Handling content from strangers — SitePoint](https://www.sitepoint.com/handling-content-from-strangers/)**
>
> Read Handling content from strangers and learn with SitePoint. Our web development and design tutorials, courses, and books will teach you HTML, CSS, JavaScript, PHP, Python, and more.

hth,  
Bill
