0

I have some an ajax script running that lets users search a dbase table of contacts and then click on the contact to whom they want to email some text. The link to send the text to the contact is just an anchor link in the results with the text passed as a variable in the url. Then on the server side, the server emails the text to the contact's email address.

The problem I have is that if the text exceeds a certain length instead of remaining hidden in the url, it becomes visible on the page. Then the script no longer works correctly. At first, I thought the problem might be due to a special character in the text corrupting the url of the anchor link but that doesn't seem to be it...It's just a matter of length.

I found this posting

that says there is not supposed to be a limit to the querystring. However, In my case, the problem occurs even before trying submit the querystring as it pops out of the url and is visible on the page. Since it is in an url going to the server I cannot think of a good way to pass the lengthy text value outside the url,

Has anyone run across this problem and if so can you suggest a workaround?

Here is example.

a href="sendemail.php?contactid=33&text=HERE IS SOME SHORT TEXT">Send to Harry</a> //works

a href="sendemail.php?contactid=33&text=HERE IS SOME REALLY LONG TEXT THAT GOES ON AND ON.....ON AND ON.... ON AND ON....ON AND ON....PAST A FEW HUNDRED CHARACERS">Send to Harry</a>  // "HERE IS SOME REALLY LONG TEXT etc." IS VISibLE ON PAGE
Community
  • 1
  • 1
user1904273
  • 4,562
  • 11
  • 45
  • 96

1 Answers1

0

Testing both of your links in this jsfiddle: http://jsfiddle.net/rzj6n/ everything is fine, your issue must be elsewhere.

However if you want to avoid very long querystrings you may want to use a form to POST data instead of using a GET.

<form action="sendemail.php" method="POST">
    <input type="hidden" name="contactid" value="33" />
    <input type="hidden" name="text" value="here is some text..." />
    <input type="submit" value="Send to Harry" />
</form>

Then you will need to access passed values with $_POST['contactid'] and $_POST['text']

Frederik.L
  • 5,522
  • 2
  • 29
  • 41
  • You are right. Realized the problem is not length of value but a special character. I have a " in there and it is what is causing the value to show on the page outside the url. You don't know the right way to escape a quote by any chance? I tried escape(string) where string is the whole string and it inserted %20 etc. between words but it did not fix quote marks. Still not displaying right. – user1904273 Dec 26 '12 at 02:16
  • try encodeURIComponent(querystring); which will give you %22 for double quotes – Frederik.L Dec 26 '12 at 07:21