views:

132

answers:

4

Hi guys,

Probably, this question has been asked before, though, I'll ask it again.

Currently, I'm facing a problem with form encoding. When posting my form, all spaces are replaced by the "+" character. I would like to replace this "+" character by a real space.

Does someone has a PHP solution for this?

Thanks in advance.

Cheers, Lennart

A: 

Can't reproduce

<form>
<input type=text name="a" value="text with spaces">
<input type=submit>
</form>
<?php if (isset($_GET['a'])) echo $_GET['a'] ?>

no spaces at all. What i m doing wrong?

Col. Shrapnel
A: 

This shouldn't happen if the browser behaves correctly. My assumption would be that a javascript is messing with your data. Replacing spaces with pluses is done when encoding urls, maybe that will help.

You can use firebug to check for any js interference.

soulmerge
A: 

Mmm...i haven't thought about the javascript factor.

I'm using AJAX (x = in this case JSON) for handling the form posts etc, so there might be some interference somewhere?

Are there some functions in js available who do the trick for me?

Lennart
Please do not post comments as answers, use the `add comment` button. This way I get notified whenever you are responding to my answers, too.
soulmerge
@downvoters: No need to downvote, though. You can't expect everyone with rep 1 to know usage of stackoverflow.
soulmerge
A: 

I'm using AJAX (x = in this case JSON) for handling the form posts etc

Then let's see the code.

Possibly you're doing something like trying to form-encode your data manually before another component also form-encodes it. Replacing a space with + is quite standard and expected for form-encoding, but if you accidentally do it twice then you're going to be left with an encoded + at the end of it.

If you are using the JavaScript escape function: don't. (When you need to URL-encode a form value for inclusion in a parameter, the proper method is encodeURIComponent. escape is a fruity non-standard encoding of its own which you should almost never have any need to use.)

bobince