aooga Posted May 21, 2009 Share Posted May 21, 2009 I have a textbox where the user inputs data which is sent to another php file. When the user types in hebrew, it is transferred correctly with POST but not with GET. With POST I get א (the correct input) and with GET I get ×. How can I get it to work with GET? I've isolated the problem to as little code as I can (the actual application uses ajax), here it is: test.php: <script type="text/javascript"> function process() { input = document.getElementById("input").value; url = "test2.php"; url += "?input=" + input; window.location.href = url; } </script> <form action='test2.php' method='post'> <textarea id = 'input' name = "input"></textarea> <input type="submit" value="Click here to POST" /> </form> <a href="javascript:process()">Click here to GET</a> test2.php just gets the get or post. <?php $input2 = $_POST['input']; $input = $_GET['input']; echo $input; echo $input2; ?> Quote Link to comment https://forums.phpfreaks.com/topic/159171-_get-and-_post-with-foreign-languages-specifically-hebrew/ Share on other sites More sharing options...
Adam Posted May 21, 2009 Share Posted May 21, 2009 You could try passing the string through JavaScript's escape function: window.location.href = escape(url); I've got little experience with this though so I don't know if it will work... Quote Link to comment https://forums.phpfreaks.com/topic/159171-_get-and-_post-with-foreign-languages-specifically-hebrew/#findComment-839450 Share on other sites More sharing options...
CarbonCopy Posted May 21, 2009 Share Posted May 21, 2009 Javascript should encode the get data with escape before sending the data http://www.permadi.com/tutorial/urlEncoding/ Then on the PHP side of things, decode the get data with urldecode http://ca3.php.net/urldecode Remember, Google is our friend Quote Link to comment https://forums.phpfreaks.com/topic/159171-_get-and-_post-with-foreign-languages-specifically-hebrew/#findComment-839458 Share on other sites More sharing options...
Adam Posted May 21, 2009 Share Posted May 21, 2009 You could try passing the string through JavaScript's escape function: window.location.href = escape(url); I've got little experience with this though so I don't know if it will work... Oops, just realised I showed you the escape function in the wrong place, should be: input = escape(document.getElementById("input").value); Quote Link to comment https://forums.phpfreaks.com/topic/159171-_get-and-_post-with-foreign-languages-specifically-hebrew/#findComment-839471 Share on other sites More sharing options...
aooga Posted May 21, 2009 Author Share Posted May 21, 2009 Didn't work for me: now I get '%u05D0' <script type="text/javascript"> function process() { input = document.getElementById("input").value; url = "test2.php"; url += "?input=" + escape(input); window.location.href = url; } </script> <form action='test2.php' method='post'> <textarea id = 'input' name = "input"></textarea> <input type="submit" value="Click here to POST" /> </form> <a href="javascript:process()">Click here to GET</a> <?php $input2 = $_POST['input']; $input = $_GET['input']; $input = urldecode($input); echo $input; echo $input2; ?> Quote Link to comment https://forums.phpfreaks.com/topic/159171-_get-and-_post-with-foreign-languages-specifically-hebrew/#findComment-839478 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.