PDA

View Full Version : htmlText pulled from msql???


charlesshoults
08-24-2008, 05:14 PM
I'm in the process of building a custom forum for a themed-website. The forum is built by hand, entirely with Flex Builder 3. I have a submission form used to compose messages, title, category and body. It collects the usual data such as composer, datetime and sends it to a php script which then stores it in the database. The problem is when I try to read the data back and display it in <mx:TextArea>. The categories populate automatically, it retrieves all message information related to the category and for each message, displays the author, when it was posted and the subject. Clicking on the message brings it down to a field below, sort of like a preview pane of an email application. All works fine as long as I strip the htmlText formatting out of the body, but if I leave it in place, nothing appears in the body field.

Can anyone help me figure this one out?
This is essentially what I have:
var msgSource:String = dataGrid.selectedItem.poster;
var msgTime:String = dataGrid.selectedItem.data;
var msgSubject:String = dataGrid.selectedItem.subject;
var msgBody:String = dataGrid.selectedItem.body;
try{ threadHeader.dataProvider.removeAll(); } catch(error:Error){}
threadHeader.dataProvider.addItem({threadPoster: msgSource, threadTime: msgTime, threadSubject: msgSubject});
for (var i:int = 0; i < msgSep.length; i++){
if(msgSep[i][2]==msgSubject && msgSep[i][1]==msgSource){
dispText.htmlText = msgBody.toString();
}
}

I have tried splitting the string into elements and then concat them back together. I've tried using myHtmlText as a source for dispText, and updating myHtmlText instead, but no difference.

The string of text pulled from mysql looks like the following:
<TEXTFORMAT LEADING=2><P ALIGN=LEFT><FONT FACE=Myriad Web SIZE=12 COLOR=#000000 LETTERSPACING=0 KERNING=0>This text should display with html formatting, but doesn't appear at all.</FONT></P></TEXTFORMAT>

I find that if I strip out the tags leading up to the actual message, then the message appears fine. I have already run a split.join on it to remove the \" associated to each tag, but it didn't seem to make a difference before or after.

Here is my project: http://www.battletech-live.net

charlesshoults
08-26-2008, 04:13 AM
It was unexpected to discover that htmlText depends very little on what source the data is coming from. I decided that until I get it figured out, I'm just going to use plain text fields for collecting and displaying the information. I changed the fields but forgot to change the HTTPService, discovering that the data getting passed to mysql still listed the surrounding code.

It makes sense how to pull the text from mysql through php and I can display it as an alert, but still, when I try to put it back into a textArea field, I get nothing.

swivelmaster
08-26-2008, 06:47 PM
You're expecting too much of HTMLText. It only really is capable of using a few specific html tags... everything else will be ignored. Leading, font face, stuff like that, I'm pretty sure will *never* work. You can get bold, italic, underline, color, size, and a few other things.

drkstr
08-26-2008, 09:25 PM
You're expecting too much of HTMLText. It only really is capable of using a few specific html tags... everything else will be ignored. Leading, font face, stuff like that, I'm pretty sure will *never* work. You can get bold, italic, underline, color, size, and a few other things. That's not true at all. Limited yes, but not that limited.


The problem you're having is because you stripped the quotes out of the string when you saved it to your DB. You shouldn't need to find and replace anything on the client side. Just escape (not remove) the quotes on the server end before storing the data. You will notice that the following string will show up just fine as htmlText:

<TEXTFORMAT LEADING='2'><P ALIGN='LEFT'><FONT FACE='Verdana' SIZE='12' COLOR='#000000' LETTERSPACING='0' KERNING='0'>This text should display with html formatting, but doesn't appear at all.</FONT></P></TEXTFORMAT>

Just make sure you are storing and retrieving the exact same string and you will be fine, regardless of the storage method.


Best Regards,
~Aaron

*edit*
Also, FYI. To get plain text from htmlText, you just need to reference the TextArea.text property. No need to do any messy stripping.

charlesshoults
08-26-2008, 09:30 PM
Font size, color, bold, italic, and underline are all I really want anyway.

If you say:
x = "I am Bob.";
y = x.htmlText;
mx.controls.Alert.show(y);
Why does it bother throwing all of the extra stuff into it, if it can't be put back into a field set up for htmlText?
It seems like kind of a waste.

<TEXTFORMAT LEADING=2><P ALIGN=LEFT><FONT FACE=Myriad Web SIZE=12 COLOR=#000000 LETTERSPACING=0 KERNING=0>I am Bob.</FONT></P></TEXTFORMAT>

swivelmaster
08-26-2008, 09:39 PM
Where's the documentation of what it can and cannot do?

drkstr
08-26-2008, 09:43 PM
Where's the documentation of what it can and cannot do?

http://livedocs.adobe.com/flex/3/html/textcontrols_04.html


Why does it bother throwing all of the extra stuff into it, if it can't be put back into a field set up for htmlText?
It seems like kind of a waste.

Again, the tags your using are valid. You're just stripping the quotes which is causing a parse error when trying to read the attributes. If you escape your quotes instead of stripping them when you save it to the DB, you'll be fine.


Best Regards,
~Aaron

swivelmaster
08-26-2008, 11:50 PM
Ah, I was unaware that those tags were supported. My bad.

It's still fairly limited, but all the tags in the original example are valid.

charlesshoults
08-28-2008, 01:19 PM
So far, htmlText has been failing to act how I need it to. I find that if I move directly from my rich text entry form to the text area I want it to appear in, it displays exactly as it should. Basically just saying b = a, I get color text, bold and italic as well as specific text size and embedded html tags. However, I find that if I pass the submitted text to mysql, or to a string variable, then back to the text area field, nothing appears. In these cases, it encapsulates the text in the necessary html tags such as <TEXTFORMAT LEADING=\"2\"> (whichever direction the slashes actually go) to the original content. When I try to send it to the text area field, with or without escaping the quotes, or with the quotes removed entirely, nothing appears in the text area and no error messages are generated. There must be something about the formatting of the passed text that it doesn't like.

For the time being, I've just switched to using plain text so that I can keep forward progress. I'll come back to html text later.

drkstr
08-28-2008, 05:23 PM
Just to recap, you do NOT need to make any modifications to the htmlText string in your Flex app. It will work just fine if you do not do any manual quote mangling. All you need to do is send it across the wire as is, and save it in your DB like this (assuming you're using php+mysql):

$htmlText = mysql_real_escape_string( $htmlText, $dblink );
//now store $htmlText

Not only will this protect you against mysql injection (client side escaping does not), it will also ensure the string you sent is the exact same one you get back.

There are no problems with the original tags or with htmlText in general. I use it all the time and it's very straightforward and simple. You are just trying to over complicate things which is where your issues are coming from.


Best Regards,
~Aaron