Prevent HTML use in textarea field?

Hi there,

Long time without a question, but today I wonder if there is a way to prevent editors to use HTML in textarea (and text) fields but keep available markdown?

I used to write in my template:

<?php echo kirbytext( html::decode( $page->text() ) ); ?>

I also could do a page or field method, but is it the good way?
Any help will be apreciated!


You could use ->markdown() instead of ->kirbytext()

<?= $page->text()->markdown() ?>

Edit: Nevermind, that still parses HTML. You could teach your editors to escape the HTML but I guess that’s not really what you’re trying to do here. You want to force them to not use it right?

That doesn’t remove HTML tags…

Maybe use a Kirbytext filter, then you don’t have to use it all the time. Wouldn’t work with non-Kirbytext fields…

Anyway, there is no way to prevent editors to enter HTML tags apart from telling them no to, for example in a help text. But if you can’t trust them, you have to get rid of these tags afterwards. Just like you have to escape stuff anyway when outputting your content.

That is exactly the purpose :slight_smile:

So, maybe I will keep it the way I used to. Just make it nicer by using a field method…