Jump to content

Crazy text in a field


Ryan Graybeal

Recommended Posts

have a problem I can't figure out.

 

We have an online program setup where the end-user can input text in any way they desire which means they will use a combination of crazy characters (#$^@#*$<&>&!|) plus returns for formatting. The problem is if the rule is set to recognize tagged text and then when it comes across a "<"

an &+(any character next to it) it thinks they are a HTML code or something and any text after it disappears. Or if all of the text is set to RAW then the line breaks are ignored and the <p> shows up in the text.

 

I know that 'TaggedTextFromRaw' will return the text as it was typed but I can't figure out how to use 'TaggedTextFromRaw' and recognize any line breaks "<p>" in the text.

 

Here is the code. I am pretty new to javascript so go easy on me : )

 

var nLine = new RegExp("<p>")
var Btext = TaggedTextFromRaw(Field("Bottle Text2"));

if (Btext.search("<p>") >= 1)
   return Btext.replace(nLine(TaggedTextFromLiteral("<p>")));

if (Btext.search("<P>") < 1)
   return Btext;

 

Does this make sense?

 

thanks for any help.

 

Ryan Graybeal

Link to comment
Share on other sites

Okay, if you're using FusionPro 6.0, then you can use the new TaggedTextFromRaw function. But you need to understand what it does. Basically, it converts literal, or "raw" text, which might contain special characters, into a string of tagged markup which will, after being processd by FusionPro's tagged markup parser, give you back the original text. This is useful if you are using the text in a rule with the "Treat returned strings as tagged text" box checked, because you may want to apply some other tags to change the attributes of the text, and you want those tags to be parsed as tags, but the other characters in the field to be treated literally.

 

So if you're only returning the field value, you don't need to call TaggedTextFromRaw at all. Just uncheck the box and you should be good, because that same logic gets called internally.

 

Only if you're doing something else with tags in a rule do you need to call TaggedTextFromRaw. For instance:

return '<f name="Arial">' + TaggedTextFromRaw(Field("Bottle Text2"));

Now, one of the things that TaggedTextFromRaw does is to convert newlines ("\n" in JavaScript) to "<br>" tags. NOT <p> tags.

 

So, if you're okay with <br> tags, all you need to do is this:

return TaggedTextFromRaw(Field("Bottle Text2"));

If you really want <p> tags instead of <br> tags, just do a replace:

return ReplaceSubstring(TaggedTextFromRaw(Field("Bottle Text2")), "<br>", "<p>");

But make sure that if you you add or modify any tags in the text that you do so AFTER calling TaggedTextFromRaw. Otherwise, TaggedTextFromRaw will be more than happy to convert a tag such as <p> into entities such as "<p>", and you'll get the actual <p> tag in the output instead of a new paragraph.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...