Sign in to follow this  
Talib

[web] php/AJAX plus sign issues

Recommended Posts

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 javascript, but this doesn't seem like correct solution. My Setup: IIS PHP v5.2.5 It's basically just a test server [Edited by - Talib on March 5, 2008 1:06:59 AM]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sounds acceptable. I have a 100kb page design limit (excluding user content). I'll have a look into it.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this