PDA

View Full Version : postComment.php?text=&quote;hello...&quote; will make result empty on variable text.



smansakra
12-28-2008, 10:03 AM
:confused:

hello....
i'm making post comment for my user using this method

postComment.php?targetID=11&yourTextComment=text
for the "text", i use document.getElementById('mytextareaID').value;

this method is good thing if user just input text, not html.
unfortunately, my textarea is modificated to integrated with WYSIWYG editot, of course in here the value of my textarea id is HTML text.

my problem is ,
if my user type like "hello..." on my textarea, of course the textarea value will be &quote;hello...&quote; ( as what i said before, it integrated with WYSIWYG editor)

so if my url
postComment.php?targetID=11&text=&quote;hello...&quote; it will say that my text value is empty.

CAN ANYONE HERE HELP ME?
thanks:o

smansakra
12-28-2008, 10:08 AM
i try by using "&text=encodeURIComponent(textvalue)"
but nothing fix

jscheuer1
12-28-2008, 10:52 AM
This will never work:


"&text=encodeURIComponent(textvalue)"

We may need to see the code. What you've posted so far is very confusing.

But, yes the solution is to encodeURIComponent() the value of the textarea before appending it to the URL. It would be something like so:


var URL = 'postComment.php?targetID=11&yourTextComment=';
URL += encodeURIComponent(document.getElementById('mytextareaID').value);
window.open(URL);

smansakra
12-29-2008, 11:12 AM
well, my site here using 2 files.
*postComment.html
*commentProcess.php

below is a very simple code that i use:
*postComment.html
<html>
<head><title> post comment</title>

<script type="text/javascript">

function submit_comment(){
var text=document.getElementById('comment_text').value;
if(text==""){alert('Please fill in the text');return false;}
//do ajax
var comment_ajax=createAjaxObj();//this function is on another file
var url= 'commentProcess.php?targetID=11&yourTextComment='+encodeURIComponent(text);
url +="&r="+Math.random();
//procesing ajax
comment_ajax.open('GET",url);
comment_ajax.onreadystatechange=function(){
if(comment_ajax.readyState==4 && comment_ajax.status==200){
document.getElementById('comment_result').innerHTML=comment_ajax.responseText;
}
}
comment_ajax.send(null);
}

</script>

</head>
<body>
post your comment<br>
<textarea id="comment_text"></textarea>
<input type="button" value="submit" onclick="submit_comment();"><br>
<div id="comment_result"></div>
</body>
</html>

:D really simple

then the commentProcess.php ie below:

<?php
//commentProcess.php?targetID=11&yourTextComment=hello..mytext..is ..here
$target_id=$_REQUEST['targetID'];
$text=$_REQUEST['yourTextComment'];

if($text==""){
echo "Please fill in the text comment";
exit();
}

else process_comment();

?>

:eek: really super simple! he he

THE RESULT OF MY PROCESING IS ALWAYS "Please fill in the text comment"

CAN ANYONE HERE HELP!!!??/

jscheuer1
12-29-2008, 03:27 PM
There could be other problems, but:



comment_ajax.open('GET",url);

Shouldn't be working at all, and if it is, shouldn't be passing anything to any page.

Please post a link to the page on your site that contains the problematic code so we can check it out.

smansakra
12-30-2008, 08:52 AM
hello....
it has worked....
my problem solved! :D