• 11
• 9
• 10
• 9
• 11

[web] php/AJAX plus sign issues

This topic is 3700 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 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?

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

 Nor magic quotes, learned my lesson with that long ago.

Share on other sites
It seems I have to use encodeURIcomponent() when passing my form elements to AJAX. Wonder why no tutorials mention this.

 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 on other sites
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 javascript programming may become fun! ;)

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 on other sites

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 on other sites
Sounds acceptable. I have a 100kb page design limit (excluding user content). I'll have a look into it.