Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

[web] php/AJAX plus sign issues

Started by Talib Mar 5, 2008 at 12:42 AM 8 replies 4.2k views
Original Post
Talib
Talib
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 '';
?>;


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.
Hodgman
Hodgman
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?
Talib
Talib
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.
Talib
Talib
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.
Hodgman
Hodgman
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! ;)
Talib
Talib
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.
Hodgman
Hodgman
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.
Talib
Talib
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.
ju2wheels
ju2wheels
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.