Page 1 of 1

missing form post data with special character

Posted: Thu Jan 14, 2010 12:52 am
by Mehnaz
Hi,

I am passing some value from html text area(lets say 'name') to a php script. It works fine when the name doesnt have any special character. but for the case of input data 'u&e' it is passing only 'u' and the rest is not passing in post variable.

Please help

Mehnaz

Re: missing form post data with special character

Posted: Thu Jan 14, 2010 1:07 am
by pbs
Use this function when you enter any descriptive content.

Code: Select all

 
function quote_smart($value)
{
    // Stripslashes
    if (get_magic_quotes_gpc()) 
    {
        $value = stripslashes($value);
    }
    // Quote if not a number or a numeric string
    if (!is_numeric($value)) 
    {
        $value = "'" . mysql_real_escape_string($value) . "'";
    }
    return $value;
}
 

Re: missing form post data with special character

Posted: Thu Jan 14, 2010 1:07 pm
by feden
I think you need to check character encoding. It should be UTF-8 on all files / databases

Re: missing form post data with special character

Posted: Thu Jan 14, 2010 2:51 pm
by AbraCadaver
Mehnaz wrote:Hi,

I am passing some value from html text area(lets say 'name') to a php script. It works fine when the name doesnt have any special character. but for the case of input data 'u&e' it is passing only 'u' and the rest is not passing in post variable.

Please help

Mehnaz
You need to show an example and some code. This works fine for me.

Re: missing form post data with special character

Posted: Thu Jan 14, 2010 3:52 pm
by Mehnaz
I am using Ajax with prototype to post the form request from index.php page to prefferdterm.php page like this to fill a div using "innerHTML". Here is my code

Code: Select all

<html>
    <title>Term Study Interface</title>
    <head>  
        <meta http-equiv=Content-Type content="text/html; charset=utf-8"> 
 
        <script type="text/javascript" src="prototype.js"></script>
        <LINK REL=StyleSheet HREF="style.css" TYPE="text/css">
        <script>
 
            function sendRequest() {
                $('dvloader').show() ; 
                new Ajax.Request("prefferdterm.php", 
                    { 
                    method: 'post', 
                    postBody: 'name='+ $F('name'),
                    onComplete: showResponse 
                    });
                }
 
            function showResponse(req){
                $('dvloader').hide() ; 
                $('show').innerHTML= req.responseText;
                
            }
            
            function popUp(URL) {
                day = new Date();
                id = day.getTime();
                eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=1,left=170, top=10,statusbar=0,menubar=0,resizable=1,width=1100,height=900');");
            }
 
        </script>
    </head>
 
    <body>
        <div style="display:none" id="dvloader"><img src="ajax-loader.gif" /></div> 
        <form id="test" onsubmit="return false;">
            <input type="submit" value="Enter Term" class = "enterbuttonclass" onClick="sendRequest()">
            <div><textarea name="name" rows="1" cols="12"  id = "name" class = "termclass"></textarea></div>
                    
        </form>
                
        <div id="show" ></div>
 
                
    </body>
 
</html>
 
I have included
<meta http-equiv=Content-Type content="text/html; charset=utf-8">

in index.php <head> section but in requesting page only 'u' out of 'u$e" is passing. When I checked the passed value in prefferdterm.php using the code below:

$term = $_POST["name"];

echo $term;

In outputs only 'u' instead of 'u&e'.

In my case user can use any sepcial character in the input form but I am stuck how to deal with it.

Mehnaz

Re: missing form post data with special character

Posted: Thu Jan 14, 2010 4:03 pm
by AbraCadaver
This is a javascript or ajax problem. Since you are posting with javascript, you need to run the data through javascript escape(), or your ajax library may have a method for encoding the data.

Re: missing form post data with special character

Posted: Thu Jan 14, 2010 4:41 pm
by Mehnaz
Thanks for all the replies.

javascript escape() did my job :)

mehnaz