How to prevent the HTML editor appearing for certain pages? (Developer question)
回帖数: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.
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)
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)
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...)
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
Re: How to prevent the HTML editor appearing for certain pages? (Developer question)
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.
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)
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 -
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
Re: How to prevent the HTML editor appearing for certain pages? (Developer question)
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