Page 1 of 2
Live preview: parsing carriage returns
Posted: Sun Sep 04, 2005 2:07 pm
by Fourtet
how would I go about registering line breaks in a rpc preview?
I tried using nl2br() server side, it didn't work though so i'm guessing the carriage returns aren't being sent in the http request, i assume therefore it has to be done clientside?
Posted: Sun Sep 04, 2005 2:13 pm
by feyd
what's your response handling code?
Posted: Sun Sep 04, 2005 2:18 pm
by Fourtet
All i'm doing is simply applying .innerHtml to a div node
so i thought if i nl2br'ed it server side it would register the breaks client side - but i dont think it's getting the carriage returns when it's first being sent with xmlhttprequest.. i'm just sending a get request with the value of the input field, then printing that value back to my callback function and attaching it to an empty div.
Posted: Sun Sep 04, 2005 9:47 pm
by Fourtet
Hmm I guess it's hard for you to say without seeing the whole source. I think I've come across a decent blog post which will help so ill post if theres any solution.
Perhaps instead someone could help me solve this bug. for some reason on my live search script which uses divs within an iframe - it doesn't assign the onclick to the first div so when you click on the first search result it doesnt close the div, but fine on the rest of them. (
http://diabli.com/gs/livesearchIFRAMEv3.htm)
Result of what happens (first 2 divs)
Related code:
Code: Select all
// looping through database query setting up the divs in an array
$results[] = "<div id=\"$id\" onClick =\"var qObject = parent.document.getElementById('q'); qObject.value = '$title'; var searchResultObject = parent.document.getElementById('searchResult'); searchResultObject.style.display = 'none';\" onMouseOver=\"this.className='alt2'\" onMouseOut=\"this.className='alt1'\" class=\"alt1\"><b>$title</b>: $description</div>";
// array into one string
$t = implode("\n", $results);
// echo callback function to browser with divs string in
echo "<style type=\"text/css\" media=\"all\"> @import \"../hotjobz/resource/hotjobz.css\"; </style><body onload='window.parent.rpcHandler(\"1\", \"$t\")'>";
Posted: Sun Sep 04, 2005 10:26 pm
by feyd
Javascript Console wrote:Error: missing ) after argument list
Source Code:
window.parent.rpcHandler("1", "<div id="" onClick ="var qObject = parent.document.getElementById(
result after pressing '1' on first load of the page.
Posted: Mon Sep 05, 2005 12:55 am
by Fourtet
That's bizarre, look at my source - there is an end bracket.

Posted: Mon Sep 05, 2005 12:59 am
by feyd
mind posting the code it would actually send?
Posted: Mon Sep 05, 2005 1:20 am
by Fourtet
It's in the php above ^
Posted: Mon Sep 05, 2005 1:22 am
by feyd
there's no window.parent.rpcHandler ... so it's not what I'm looking for.

Posted: Mon Sep 05, 2005 1:41 am
by Fourtet
There is - it's there but it's done something strange with the bb code lol - try selecting some text and dragging down on the php bit.
Posted: Mon Sep 05, 2005 1:49 am
by feyd
mm yes, forgot that bit.. well.. if you look at the output, it's error'd though.. watch:
Code: Select all
<style type="text/css" media="all"> @import "../hotjobz/resource/hotjobz.css"; </style><body onload='window.parent.rpcHandler("1", "<div id="" onClick
="var qObject = parent.document.getElementById('q'); qObject.value = ''; var searchResultObject = parent.document.getElementById('searchResult'); sea
rchResultObject.style.display = 'none';" onMouseOver="this.className='alt2'" onMouseOut="this.className='alt1'" class="alt1"><b></b>: </div>")'>
(the varialbes are missing)
Do you see all the unescaped quotes?
try this:
Code: Select all
// looping through database query setting up the divs in an array
$results[] = "<div id=\\\"$id\\\" onClick =\\\"var qObject = parent.document.getElementById('q'); qObject.value = '$title'; var searchResultObject = parent.document.getElementById('searchResult'); searchResultObject.style.display = 'none';\\\" onMouseOver=\\\"this.className='alt2'\\\" onMouseOut=\\\"this.className='alt1'\\\" class=\\\"alt1\\\"><b>$title</b>: $description</div>";
// array into one string
$t = implode("\n", $results);
// echo callback function to browser with divs string in
echo "<style type=\"text/css\" media=\"all\"> @import \"../hotjobz/resource/hotjobz.css\"; </style><body onload='window.parent.rpcHandler(\"1\", \"$t\")'>";
[edit] scrap that, it still won't work.. You're mixing both types of strings... That should really be put into a JS function that's not inlined.. or change all the single quote string bits to double quote ones.. (if possible)
Posted: Mon Sep 05, 2005 2:35 am
by Fourtet
Hmm, I still don't understand why it displays ok on the rest of them though. Surely if there was a problem in the escaping it would fail to print the variables on all divs.

Posted: Mon Sep 05, 2005 2:48 am
by feyd
it's a mirroring effect, I'd imagine. Try this to find out: remove all but 1 of them. If I'm right, it should break, as would all odd numberings of it.
Posted: Mon Sep 05, 2005 6:47 am
by Fourtet
You are right about that. I really shouldn't have it printing from the php page, not exactly a good model is it - anyway it was just lazy programming.

i will add another abstraction layer i suppose.
Posted: Thu Sep 08, 2005 8:17 am
by $var
i have seen it written that in the INSERT line, there is simply something like
'".str_replace("'","'",'<br>',$_POST["password"])."'
the ' replaces apostrophies, so that when an entry is made, it can display again without f*ing up the code.