I am working with Zend Framework. I have a form with some fields, all of them type="text"
, including an input called "Telephone". When submit, I am using Ajax to send data to Controller. Well here is my problem, if I type a +
symbol, for example:
+34-666666666
the data I receive is 34-666666666
. The +
symbol turns into a whitespace. This problem only happens with +
, I have tried with all the symbols and theres no problem. I am going mad and I didn't found any solution in Google.

- 25,778
- 6
- 72
- 93

- 105
- 1
- 2
- 8
-
2How exactly are you submitting the data? – deceze Jun 14 '12 at 08:39
2 Answers
The +
symbol is used in URL's to represent whitespace. Your ajax submit is probably performing a GET request and the +
in the URL string is getting transformed.
Sanitize your input via javascript before submitting the ajax request with encodeURIComponent()
.
You might also find this question useful: Plus character in URL transformed to space on a linux box.
This question discusses encodeURIComponent
: How to encode a URL in Javascript?

- 1
- 1

- 27,550
- 11
- 97
- 161
You need to encode your GET/POST data as described here. The JavaScript encodeURIComponent
function can be used with a little twist*:
For application/x-www-form-urlencoded (POST), per specs, spaces are to be replaced by '+', so one may wish to follow a encodeURIComponent replacement with an additional replacement of "%20" with "+".
"&phone=" + encodeURIComponent("+34-666666666").replace(/%20/, "+"); // "&phone=%2B34-666666666"
"&phone=" + encodeURIComponent("+34-666666666 x123").replace(/%20/, "+"); // "&phone=%2B34-666666666+x123"
*Note: treatment of +
character in a URL varies depending on whether it is used inside a path component or query string:
http://example.com/page+1
-- file namepage+1
http://example.com/page%201
-- file namepage 1
http://example.com/?file=page+1
-- query string parameterfile=page 1
http://example.com/?file=page%201
-- query string parameterfile=page 1

- 262,204
- 82
- 430
- 521