[web] php/AJAX plus sign issues

Started by
8 comments, last by Talib 16 years, 1 month ago
Hi I've googled everywhere for an answer and couldn't find a definitive one. I have simple textbox which I then POST. However, when I type a plus sign into the textbox it is translated to a space. OK, so from what I've read, the plus sign is also used to represent a space in a URL. OK, good enough I understand. And also according to most people I should use urlencode() as used in the example provided by documents of urlencode():

<?php
echo '<a href="mycgi?foo=', urlencode($userinput), '">';
?>;


But how do you apply this to a form? I've also read somewhere that the browser is suppose to encode the plus sign (I am not sure how correct this is). I can manually replace plus signs with &#106avascript, but this doesn't seem like correct solution. My Setup: IIS PHP v5.2.5 It's basically just a test server <!--EDIT--><span class=editedby><!--/EDIT-->[Edited by - Talib on March 5, 2008 1:06:59 AM]<!--EDIT--></span><!--/EDIT-->
Try, try and fucking try again.
Advertisement
I just did a test on my PHP server, and the form data arrives in my php script's $_POST correctly as '+', not as ' '.

What browser are you using, what does your form's HTML look like, and how are your receiving the POST data in your PHP script?

[EDIT]Also, do you have magic_quotes_gpc set to On in your php.ini file?
Stupid me, did the same simple experiment and walla it worked.

I forgot to mention that the textbox uses AJAX, so that seems to be where the problem is.

Might it be that browser doesn't encode posted data that is sent with AJAX?

BTW I am using Firefox 2.0.0.12

[Edit] Nor magic quotes, learned my lesson with that long ago.
Try, try and fucking try again.
It seems I have to use encodeURIcomponent() when passing my form elements to AJAX. Wonder why no tutorials mention this.

[edit] Anybody that is experienced with AJAX, do you this with all your text fields or is there another solution or am I doing something wrong?
Try, try and fucking try again.
I use the Prototype library when doing AJAX stuff - it has functions that automatically encode all my forms for me.


I warn you though, if you start using Prototype then &#106avascript programming may become fun! ;)
Looks interesting, I'm just worried about excessive code loading. South Africa is not famous for lightning fast internet. Thus I'm worried about my pages having to load the entire API.

How does prototype affect page loads?
Try, try and fucking try again.
Its about 30kB.

If your pages have 500kB of images on them, then it won't really make a difference.
But if your pages are only 10kB then it will make a big difference!

[EDIT]If your web-server is set up correctly though, each visitor should only download the .js file once, so it should only slow down their loading times the first time they visit the page.
Sounds acceptable. I have a 100kb page design limit (excluding user content). I'll have a look into it.
Try, try and fucking try again.
If I recall correctly, the + should only be changed to an empty space in the case of a GET request, not a POST as these are passed in the header as is.
It's happening with posts (Edit: AJAX only) as well, I found the following blog that helped:

http://matthom.com/archive/2006/07/08/more-ajax-post-over-get

and

http://matthom.com/archive/2006/07/08/&#106avascript-function-to-the-rescue</a>
Try, try and fucking try again.

This topic is closed to new replies.

Advertisement