Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am using Drupal 7.0 and I needed to display CK editor inside a text-area.In Drupal 6 there is option to display the textarea using visibility settings.But in Drupal 7 there is no such option.So how can i bring the CK editor inside the text-area in drupal 7?.I have installed CK editor module 7.x-1.x-dev.Any help is very much appreciated.Thank you
Comments
Comment #1
dczepierga CreditAttribution: dczepierga commentedDo you use any type of text format (input format) in this textarea?
Comment #2
nidhijsen CreditAttribution: nidhijsen commentedI got this problem fixed..
I just typed the following code in my form for the text-area field.
'#type' => 'text_format'
Then the ckeditor was displayed inside the textarea with the default 'Text format' selected(I am using 'full html').
I hope this helps someone.
Thank you.
Comment #3
dczepierga CreditAttribution: dczepierga commentedInstead of this u could add:
Then CKEditor should work too and attach to this textarea.
Greetings
Comment #4
bzrudi CreditAttribution: bzrudi commentedHi,
sorry for posting in already closed thread. I have the same issue as above while making the switch from D6 to D7. I use an own module with a simple textarea form and ckeditor does not show up.
I tried setting the mentioned parameters:
'#format' => 'full_html' -> does not show up
'#type' => 'text_format' -> gives me the select box below the textarea but ckeditor still does not show up
Also I tried some more (not well in API documented) parameters like:
'#input_format' => 'xyz' -> no result even the filter format is defined. And a call of filter_default_format() gives me the expected result
I also played with:
'#text_format' => 'xyz' -> even no result.
Ckeditor itself is working as expected in all other textareas like body_field and contact and so on, just my own simple defined textarea form which did it flawless in D6 is no longer working...
Any ideas?
Thanks!
cheers bzrudi
Comment #5
bzrudi CreditAttribution: bzrudi commentedHi,
nevermind, it works with a clean install of D7. So it seems its an problem with the update and the used filters or whatever, will get rid of it ;-)
Thanks anyway
Comment #6
Petrica CreditAttribution: Petrica commentedHere's an exact syntax taken from my custom module:
Where "full_html" is the id of the Text format.
Cheers.
Comment #8
nidhijsen CreditAttribution: nidhijsen commentedLast comment deleted.
Comment #9
nidhijsen CreditAttribution: nidhijsen commentedComment #10
jeff.maes CreditAttribution: jeff.maes commentedThe code below works for:
Comment #11
carvalhar CreditAttribution: carvalhar commentedhi,
i'm using this code, ckeditor appears ok, but when i save i get this error:
Do you know why? The form is always empty
Comment #12
nymo CreditAttribution: nymo commentedSame for me, it returns an array for some reason. Although, you are specifying #type twice...
UPDATE: the value saved for #text_format is indeed an array containing keys for 'value' and 'format'.
Comment #13
carvalhar CreditAttribution: carvalhar commentedopening it...
Comment #14
bel.inna CreditAttribution: bel.inna commentedWarning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1552 of includes\bootstrap.inc).
Have the same problem
Comment #15
thaistore CreditAttribution: thaistore commentedthis just sucks! it does not show up, what I need to do, delete all the files, what a bout database?
Comment #16
StephenRobinson CreditAttribution: StephenRobinson commentedI used the following code to get an editor up on a profile field "field_profile_about":
Comment #17
Navneet.Chauhan CreditAttribution: Navneet.Chauhan commented$form['formItem'] = array(
'#type'=>'text_format',
'#title' => t('Field Label'),
'#value' => 'This is my value',
'#format'=>'full_html',
);
yes! It works. Thnks petrica
Comment #18
anil_89 CreditAttribution: anil_89 commentedIt is working fine.
'#type' => 'text_format', in form array instead '#type' => 'textarea',
and also you can define format of editor
by "#format" = > "full_html"
$form['formItem'] = array(
'#type'=>'text_format',
'#title' => t('Field Label'),
'#value' => 'This is my value',
'#format'=>'full_html',
);
Thanks
Anil Rawat
Comment #19
jcisio CreditAttribution: jcisio commentedRevert the status as it was reported working (#17, #18).
Comment #20
dariusa CreditAttribution: dariusa commentedI'm getting this issue too...so there's definitly something going on...
Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1552 of includes\bootstrap.inc).
Please leave open until a resolution appears?
Update:
The issue for me seems to be centered around modifying an instance form:
$form['instance']['label'] = array(
'#type' => 'textfield',
'#title' => t('Custom Display label'),
'#description' => t('Lable to appear in form.'),
'#default_value' => isset($form['#instance']['label']) ? $form['#instance']['label'] : '',
'#weight' => $form['instance']['label']['#weight'] + 1,
'#maxlength' => '500',
'#format' => $tmp['format'],
);
I can solve this issue for myself by moving the form outside of the instance and using the solution found here: http://drupal.org/node/1355242#comment-6086212
$tmp = variable_get('lable', array('value' => '', 'format' => NULL));
$form['label'] = array(
'#type' => 'textfield',
'#title' => t('Custom Display label'),
'#description' => t('Lable to appear in form.'),
'#weight' => $form['instance']['label']['#weight'] + 1,
'#maxlength' => '500',
'#default_value' => $tmp['value'],
'#format' => $tmp['format'],
);
But the solution will not work if I bring the element inside the instance...
Comment #21
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedNo answer here quite solved the issue for me. I had to come up with another solution that uses a few snippets from here as well as some of my own discoveries. This really almost needs to be a bug since the setting should be configurable or easily done at least. As per ckeditor documentation,
Drupal.ckeditorInit('$element_id');
should be enough, but it isn't. Things have to be initialized from PHP and there is no easy to use function to do it. The link below was the solution I came up with, hope it helps someone else.http://drupal.stackexchange.com/a/62452/13763
Comment #22
cilefen CreditAttribution: cilefen commentedCKEditor fields store the form value differently than a plain textarea. To display the value you have to use something like this:
The key thing is ['element']['value'] instead of ['element'].
Comment #23
xuxizh CreditAttribution: xuxizh commented$form['formItem'] = array(
'#type'=>'text_format',
'#title' => t(''),
'#value' => $default_value,
'#default_value' => $default_value,
'#format'=>'full_html',
'#attributes'=> array('id' => array('basictext')),
);
with this '#attributes', the ckeditor is not show up in drupal 7.22, but removed this '#attributes' line, what's wrong ?
Comment #24
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedxuxizh, you will likely need to approach it using the solution I came up with here:
http://drupal.stackexchange.com/a/62452/13763
This method should work on any form every time if you implement it correctly. What you attempt in your above will not necessarily load the prerequisites.
I am also re-opening this issue, as the issue is deeper than a workaround as mentioned in #17/18 that only works whenever there is already a reason for the ckeditor to be loaded elsewhere on the page. Changing title to reflect what the nature of this request is as well.
There needs to be a simple hook, callback or documented way to properly enable CKEditor on a specific textarea. The stackexchange answer I linked above could be something that would allow creating this sort of callback.
Comment #25
merzikain CreditAttribution: merzikain commentedWhen you say "enable CKEditor on a specific textarea", do you mean using FAPI or something else?
If you're talking about just using the Form API: https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...
That works perfectly and I see absolutely no reason for all of the confusion and issues here.
The only thing you have to keep in mind is that field is stored as an array containing the value the user inputs and the format that value was stored as.
So when rebuilding the form with previously input data (such as with a settings form or content editing form) you just do something like this:
The stackexchange solution you linked is a "small problem, big solution" kind of thing unless I'm missing the point of what you're trying to do.
Comment #26
jnavane CreditAttribution: jnavane commentedYes.. This is what I need.. Thanks for your post.
Comment #27
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedmerzikain, try to enable ckeditor on the textarea in the stackexchange answer using your method and you will see why the solution was required. Perhaps it is just that particular textarea but it is certainly the best way to get it working for the
webform_email_edit_form
form's$form['template']['template']
field. If you have any insight on this then please let us know.Comment #28
merzikain CreditAttribution: merzikain commentedTo be fair, both your situation and the situation in the drupal stackexchange are different from what is being asked for here. I posted the solution for this issue there only to help people with the problem expressed here who stumble upon that answer in their Google searching.
If someone is attempting to change a module administration form textarea your solution is the one to go with since it's the only way to do it.
But again that works as designed since module developers who put textareas in their admin forms and DO NOT set it to be a WYSIWYG enabled field likely did so on purpose and changing it could break things in the module, though not in your specific case.
The way the webform module intends the E-mail template field to be used is to provide the plain text message there and then setup your own (or use the default) email template file to wrap around that message, thereby negating the need for it to be a WYSIWYG enabled field.
You could probably post your concerns about it in the webform module and request they give the field the ability to switch between the two. If they don't like the idea they may go into more detail on why they opted to not do it in the first place.
So to sum up, if you're modifying a module generated form that is not your own, use nicholas' method. Otherwise use the FAPI method.
Comment #29
nicholas.alipaz CreditAttribution: nicholas.alipaz commentedmerzikain, thanks for the explanation. That does sum it up a bit better. I do however think this could be somehow documented in ckeditor's documentation.
Adding ckeditor to your own FAPI forms:
...
Altering FAPI forms provided by other modules to use ckeditor:
...
With the corresponding explanations of course. But with or without the explanation I am just glad that this page and the stackexchange page both exist so people can find information through search at least.
Comment #30
谢艳 CreditAttribution: 谢艳 commentedIs it possible to configure CkEditor to use a specific form element ID?
Comment #31
phponwebsites CreditAttribution: phponwebsites commentedI've used below codes in my custom form:
I could get only value.
ie,
I couldn't get safe_value in form submit.
ie,
Comment #32
scaballeronavia CreditAttribution: scaballeronavia as a volunteer commentedThank U, phponwebsites
Comment #33
millisaeubanks CreditAttribution: millisaeubanks commentedMy editor is showing up in my module, but when I add a image using the media browser it is only outputting the [["fid"...]] string instead of the image. Looking at the variables set I am only getting the value and not the safe_value that has processed data like that above into their respective HTML content. I have checked under text formats and for the full_html format I have the setting "Convert Media tags to markup" checked. I am just not sure why that doesn't appear to be getting done.