Jump to content
FrancisChung

Converting HTML entity characters

Recommended Posts

Hi there,

Bit of a rookie question. It appears that one of my users tried to store some Markup in a Textarea field for some SEO Text, but it was stored as HTML Entity chars (< >) 

I checked the field type details (TextArea, No Formatters, Content-Type:Unknown) and tried a few things (TinyMCE, Markup/HTML Type) to no avail.

I was wondering if there's a quick fix for this as I'm almost resigned to writing a on-the-fly formatter to fix this.

I'm hoping some one can point me to a more CMS centric solution?

Share this post


Link to post
Share on other sites

What exactly do you mean by quick fix? Getting rid of those characters? Getting rid of the html encoding? Removing the ability to add those characters?

Share this post


Link to post
Share on other sites

Ideally storing them as <html> tags instead of html entity encoded characters as they currently are.

Perhaps it's stored that way as some sort of security measure?

If so, is there a built-in function or something in the backend to read them as decoded HTML characters so the text gets formatted by the browser?

Share this post


Link to post
Share on other sites

Have you actually been able to reproduce the problem?

I'm asking this because it's not clear to me if it was the user who posted the data like that, or if that's how the data gets stored in the database, or if you mean that when you try to print the value of the field in your program, it comes out as < instead of < on your screen. It's not even clear if the user who posted the data used a custom form or the PW admin.

To answer your question, there is of course http://php.net/manual/en/function.html-entity-decode.php, which can also be used through PW like this

$sanitizer->unentities($text);

However I don't think it's the right approach - to me it sounds like you have a problem elsewhere. Maybe you are encoding the value twice. Could you please post us some bits of code which demonstrates your problem? I'm quite sure we can then easily help you fix your problem. It would also help if you could paste the raw value of the field directly from the database.

  • Like 3

Share this post


Link to post
Share on other sites

The user was copying and pasting contents of a MS Word document into CMS via the Processwire Admin.

The field we're having is a SEO Text field which is setup as a Textarea (TinyMCE).

A sample of how the data looks like when viewed in the  Processwire Admin.

I believe this is the same format as the original MS Word document.

<H2>

„Wer kriecht aus dem Schneckenhaus?“ und viele weitere Sprachspiele für Dich

</H2>

 

I believe this is stored in the DB raw as 

<p><H2></p>

<p>„Wer kriecht aus dem Schneckenhaus?“ und viele weitere Sprachspiele für Dich</p>

<p></H2></p>

Perhaps the field type is wrong and there are more appropriate types?

I agree completely that I shouldn't have to do any postprocessing on the fields, which is why I came to the forum and asked for some guidance.

Thanks for the info about decoding HTML characters. Not sure why my Google-Fu was not up to scratch that day.

Share this post


Link to post
Share on other sites

@FrancisChung, perhaps I'm misunderstanding this, but I think you are saying they are pasting markup into an RTE? That could never work under any circumstances, because RTE means rich text, not markup. If they want to paste in markup, they would have to first click the code view button.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @Macrura, so what you're saying is that TinyMCE is a rich text editor field and not a HTML field editor (by default)? So a user would need to press the HTML button first before entering the markup?

I assume the code view button you mentioned is the HTML button on the TinyMCE?

Share this post


Link to post
Share on other sites

I may be misunderstanding, but why do you even use TinyMCE, which is by definition a tool to create html content. Seo fields do not support any html-tags, but only raw texts. Just use a simple textarea without any rich text gimmics, maybe add the strip tags settings and you're good to go.

Hi @Macrura, so what you're saying is that TinyMCE is a rich text editor field and not a HTML field editor (by default)? So a user would need to press the HTML button first before entering the markup?

I assume the code view button you mentioned is the HTML button on the TinyMCE?

That's right. 

Share this post


Link to post
Share on other sites

The text supplied by a SEO consultant came with HTML markup, so the users wanted to put it in as is with the markup preserved.

So would a text area been suffice? Would that show the HTML markup assuming I don't put the string tags settings in?

FYI The SEO field previously was plain text without markup, but recently changed when they hired a SEO consultant.

Share this post


Link to post
Share on other sites

Markup inside of meta tags? That sound strange. But a textarea is the best way if they are just copy pasting. It's not hiding anything and it will just save what's in it. But skip the strip markup setting in this case.

  • Like 1

Share this post


Link to post
Share on other sites
FYI The SEO field previously was plain text without markup, but recently changed when they hired a SEO consultant.


I feel your pain! Prepare for the worst :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By hellomoto
      I can't tell what's wrong; my local development version appears just fine, but I copy over the site files and db online and the homepage content is not being contained. This is what it should look like (same site in the same browser, running on my localhost): http://imgur.com/UFZFzrd
      What could be the problem here? Sorry to bring up something so irrelevant to PW here, I just know that you all are a valiant and helpful group, and no one on StackExchange seems to even know what I'm talking about.
      Thanks a lot.
    • By DooM
      Hey guys,
      I'm using Form builder module by Ryan and I'm trying to render HTML success message after form is sent using value from this field:

      but it renders exactly as it is written in the field, not as HTML. To render it I just use echo
      <?= $successMessage ?> What am I missing?
       
      Thanks for any help. 🧒
    • By Marcel
      Hey, 
      - we made a page as admins
      - as admins each  <img> tag is loaded and images are displayed
      - we tested the page as a pre-definded test user which is "guest" (Admin Theme: Reno)
      - as test user each <img> is missing and so no image is displayed
      I checked this in dev-mode on firefox and chrome. Does anyone have an idea or has had similar issues?
       
      Thank you in advance.
       
      Marcel
    • By Lemoratoire
      Hi guys, 
      For a school work, I need to be able to write my own HTML code in the editor, but when it comes to "complexe" code such as a .DIV or a SRC, the "source" page doesn't recognize it. 
      So my question is the following: Is there a possiblity for me to enable the fact that I could work on a page by using my own html, without touching the .php doc?
    • By MilenKo
      Hello guys. I feel a bit ashamed of this fact but I just needed to add an image with some text wrapped around it using CKEditor and I simply can't achieve that. I have an image field attached to the template (called images) and it is showing promptly the uploaded images. I am able to manipulate the image and I set its alignment to left side. Then I add some text and I can see in CKEditor that the text is properly surrounding the image. However, once I save the page and view it, it shows the text under the image or only a line is staying asside the image and the rest is under the image again. As far as the field used for the text (body) is set to TextMultiLang and I did not added any text formatters and chose the content type to be HTML/Markup.
      In my CSS I've added some of the PW styles for the alignement as per some posts here but that did not help either. Something I am missing again?
       
       
       
       
×
×
  • Create New...