How to prevent the HTML editor appearing for certain pages? (Developer question)

How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Dan Stowell នៅ
ចំនួនតប៖ 8
Hi - I'm creating something in Moodle which includes a form for typing in some optional custom code, using a HTML <textarea> element. (Don't worry, it's not possible to use it to execute malicious code. It's only Jmol-script.)

How can I prevent the <textarea> from automagically turning into the HTML editor? It's highly inappropriate in the case of this particular form field...

Thanks in advance.
មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Dan Stowell

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Jan Dierckx នៅ

Hi Dan,

I wasn't aware of the HTML editor automatically turning every <textarea> into a HTML editor.

If you use Moodle's print_textarea function, the first argument specifies if you want to use the HTML editor (if the user has allowed it, that is)

   print_textarea(false, 30, 65, 680, 400, "alltext", "default text"); 

will open a normal textarea with name 'alltext' and content 'default text'.

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Jan Dierckx

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Dan Stowell នៅ
Does this work for you? It doesn't work for me.

When I asked the question I was directly writing <textarea> to the page, and somehow that was automatically transformed into a HTML editor. Now, I'm doing as you say, with print_textarea(false...), and it still appears as a HTML editor! (I can prove that I'm looking at the right screen etc ញាក់ចិញ្ចើម since if I manipulate the rows/cols arguments, the box changes size...)
មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Dan Stowell

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Jan Dierckx នៅ

The example is taken from the text resource type, which AFAIK displays a normal <textarea> ... if I am looking at the right screen, that is... ញាក់ចិញ្ចើម

Don't know why it doesn't work ច្របូកច្របល់ Maybe you could look at how the text resource type displays a textarea without the HTML editor kicking in.

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Jan Dierckx

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Dan Stowell នៅ
Thanks! The clue was indeed revealed in the "text" resource type. The solution, for anyone else who may need it:

Set the *global* variable $usehtmleditor to 'summary' (i.e. the name(s) of the textarea(s) that you *do* want to be passed through the HTML editor) - if you don't do this, then by default all of the textareas are transformed.
មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Dan Stowell

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Janne Mikkonen នៅ
Don't include use_html_editor function at the bottom of your page, that should do it.

usually used:

at the top of the page:

$usehtmleditor = can_use_html_editor();

and at the bottom of the page:

if ( $usehtmleditor ) {
    use_html_editor();
}

So just leave these out and editor shouldn't appear.

- Janne -
មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Janne Mikkonen

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Dan Stowell នៅ
I'm not calling that function at all.mixed

This development is part of the "mod/resource" framework so perhaps something else somewhere is calling that function. But I've done a text search on the "mod/resource" folder and can't find a reference anywhere...


មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Dan Stowell

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Jan Dierckx នៅ

Dan,

I downloaded your jmol resource type, but couldn't find a textarea. Maybe you are referring to a new version you are working on.

$usehtmleditor is set in course/mod.php before code of the mod/resource framework is called. It is set according to the user preference. (See function can_use_html_editor() in moodlelib.php)

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Jan Dierckx

Re: How to prevent the HTML editor appearing for certain pages? (Developer question)

ដោយ Dan Stowell នៅ
Jan -

You're absolutely right. I changed it from a textarea to a one-line "input" field in order to avoid the HTML editor!

I've now found out how to solve the problem - see my reply above...

Sorry for any confusion. I've updated the CVS version (the zip download will take 24 hours to update).
មធ្យមភាគនៃរង្វាយតម្លៃ: -