1

In latest Drupal 8, I've got a text field of format Full HTML that contains <form> and <input> tags (It's a MailChimp subscribe snippet). As long as I am editing the text in CKEditor in the backend, the form is displayed correctly. But as soon as I view tha page in the frontend, both tags are stipped out. I checked my text format/CKEditor settings to see if tags are stripped out there, but "Limit Allowed HTML Tags" is unchecked. Does someone know what's happening here?

Edit: after checking out more, I realized that the text field is rendered inside a view (field based). When rendered as a node, the markup is perfectly rendered, just when rendered as a view, then the tags are stripped. I edited the question title to refelct this information. Any suggestions how to render the tags inside a view?

Edit 2: the text field is rewritten in views (added some wrapper tags).

  • did you click 'Source' in CKEditor before pasting the full html code ? – izus Jun 3 at 12:24
  • 1
    you can use webform create form include to content – vinhdv Jun 4 at 8:00
  • @izus sure, I pasted code while in source code mode. – Madam Adam Jun 4 at 13:45
  • Most often, you are unable to do this because it is not safe markup. I would suggest using webform as @vinhdv also mentioned. – Chris Happy Jun 4 at 13:58
  • 1
    What i suggest is : in views Format, do not use 'Fields' but instead use 'Content' with a custom view mode that renders the fields you want to dispaly. – izus Jun 4 at 20:16
1
+50

I confirmed on 8.7 that the following basic snippet is able to be used in Full HTML out of the box:

<form><input checked="checked" name="gender" type="radio" value="male" /> Male<br />
<input name="gender" type="radio" value="female" /> Female<br />
<input name="gender" type="radio" value="other" /> Other</form>

It's possible your particular snippet is being hit by the "Correct faulty and chopped off HTML" Format setting, so try it without that and see if it lets the code stay. Of course, this is not an ideal setting for a commonly used text format filter, so this snippet may be better off in a custom plugin block, or creating a new text format w/ the "Correct faulty and chopped off HTML" turned off, that can be used sparingly as needed.

UPDATE based on Views usage:

If you're using rewrite, it won't be possible out of the box to have it not strip tags, it's something baked into Views. You can override it at the theme layer - if for example you are using the body field, you create a views-view-field--body.html.twig file in your theme, and then put the desired wrapper tags around the {{ output -}}, e.g.:

<div class="foobar-wrapper">
{{ output -}}
</div>

And turn off rewrite in Views UI.

  • after testing your snippet, I realized that the tags aren't stripped when the node is displayed with default view mode, but when the field is rendered inside a field based view, then tags are stripped out. I edited my question regarding this new information. – Madam Adam Jun 4 at 14:24
  • Updated my answer based on your edits - please let me know if this helps to solve your issue. – Tyler Fahey Jun 4 at 15:15
  • Thank you, I see the problem now. Didn't know that rewriting was the reason for stripping. – Madam Adam Jun 5 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.