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

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

per Dan Stowell,
Number of replies: 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.
Average of ratings: -
In reply to Dan Stowell

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

per 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'.

In reply to Jan Dierckx

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

per 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 clinhada since if I manipulate the rows/cols arguments, the box changes size...)
In reply to Dan Stowell

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

per 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... clinhada

Don't know why it doesn't work incertan Maybe you could look at how the text resource type displays a textarea without the HTML editor kicking in.

In reply to Jan Dierckx

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

per 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.
In reply to Dan Stowell

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

per 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 -
In reply to Janne Mikkonen

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

per 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...


In reply to Dan Stowell

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

per 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)

In reply to Jan Dierckx

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

per 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).