Lock an element inside the textarea

Asked

Viewed 267 times

0

I need to block a part of a text that is inside ckeditor so that the user does not delete and does not change that part of the text, but it can complement the text only can not change that part

<p>Essa parte nao pode ser alterada</p> <p>Essa aqui pode</p>

Could be some code css or javascript that blocks this change ? Or would have other forms ?

1 answer

1

Ckeditor is not <textarea>, is contentEditable (or docMode), in any way I think it is impossible to prevent the user from interacting with the element, this because the control is all of the user in the contentEditable

What I recommend is to add the element later, for example at the time of sending the form or saving the form data somewhere, assuming you use PHP, so just insert when you took the data on the server, something like:

if (isset($_POST['dados'])) {
    $dados = $_POST['dados']; //Dados do textarea

    $dados .= '<div>Assinatura etc</div>'; //Adiciona uma assinatura
}

This is an example just to understand, in case of injecting in a specific place you can use DOMDocument::loadHTML to make HTML work with PHP and then use one of the following functions to select the exact location you want to inject a specific tag:

  • DOMDocument::getElementsByTagNameNS
  • DOMDocument::getElementsByTagName
  • DOMDocument::getElementById

Or use the Domxpath class to select (which is much more advanced and can simplify work depending on the complexity of the selection type):

And then with one of the following functions:

Depends a lot on the need, between these two.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.