0

This is really weird. I have a textbox inside a form. On clicking the submit button, the content of the textbox gets posted to page2.php

If the textbox contains a text like

This is a sample url 
https://maps.google.com/maps?q=karnataka+badminton+association+bangalore&ie=UTF-8&ei=w4_lUNWmJozjrAfSkYGYBA&ved=0CAsQ_AUoAA 

Now when i hit submit, i am echoing the content in page2.php and this is what i get:

//echo $_POST['message'];

This is a sample url 
https://maps.google.com/maps?q=karnataka

I am getting the message but the URL gets cut after the first '+'. Any ideas how to get this work ?

I even checked with firebug the POST request and there it correctly displays the complete url.

NEW EDIT: I am trying this with ajax now.

Abhishek Saha
  • 2,564
  • 1
  • 19
  • 29

1 Answers1

1

You should encode the url first. You can use encodeURIComponent(str) or encodeURI(str) embedded in javascript to do so. See: Encode URL in JavaScript?

You should then use urldecode/rawurldecode to decode the url into its native form. You can also store the decoded form and decode the url in php / javascript as needed. See:http://php.net/manual/en/function.rawurlencode.php

Community
  • 1
  • 1
Howard Grimberg
  • 2,128
  • 2
  • 16
  • 28
  • Appologies for my late reply. Yes, that was exactly the error. When i was passing parameters through javascript, the '+' symbol in the url was clashing with the concatenate '+' of javascript. Thanks. – Abhishek Saha Jan 12 '13 at 18:48