Jump to content

$_GET and $_POST with foreign languages, specifically Hebrew


aooga

Recommended Posts

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;

?>

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

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);

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;

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.