Drupal 6: Implement Wysiwyg on Custom Module Form - drupal

I have a custom form that I have written with the Form API. We have the WYSIWYG module and TinyMCE implemented on the site that this module will be used on. How do I implement the WYSIWYG api on my custom form text areas?
Thanks!

This should help integrate WYSIWYG with your custom module forms: http://drupal.org/node/358316
Basically, you need to add the format key to each of your form fields and use filter_form()

Just in case anybody working with Drupal 7, here's the link to it that should help integrate WYSIWYG TinyMCE with your custom form fields: http://drupal.org/node/1087468
Thanks

In case you are working in drupal 7. Use the following.
$form['FIELD'] = array(
'#type' => 'text_format',
'#title' => t('TITLE'),
'#format' => 'full_html' //the format you used for editor.
);
In your form submit handler, you can access the value as follows.
$form_state['values']['FIELD']['value'];

Related

How to use tinyMCE into sonata admin bundle

I want for all my entity properties type "text" to show a html editor(preferably tinyMCE) in the forms to create and edit.
Is there any way to do it?
I'm not sure if the text input is the best way (and possible) to represent your text editor over the textarea element using TinyMCE. Here it goes how you do it:
->add('myText', 'textarea', array('attr' => array('class' => 'tinymce', 'tinymce'=>'{"theme":"simple"}')));
You can later include TinyMCE dependencies by adding a custom template for this field with its template option (although it would be recommended to add them inside the <head> of the page)
hi first install tinycme editor bundle in your project for this please see this page
after that for using in sonata admin see this issue

How to use Wordpress Text Editor in a custom plugin

How can we use default wordpress text editor for my wordpress plugin.Any suggections please?
The WordPress Text editor is an application of the TinyMCE Editor. You can utilize the files located in wp_includes/js/tinymce and create an instance of the editor on your own, according to the documentation.
Check out this article for example instructions:
http://wordpress.org/support/topic/how-i-can-use-tinymce-for-my-own-plugin
As of Wordpress 3.3 the_editor has deprecated in favor of wp_editor. wp_editor uses the new media uploader and takes advantage of all the new features of Wordpress 3.5.x Documentation here: http://codex.wordpress.org/Function_Reference/wp_editor
A very good example of how to use it can be found at Wptuts+ here: http://wp.tutsplus.com/articles/tips-articles/quick-tip-using-wp_editor/
very easy try this code
it's working
wp_editor( $distribution, 'distribution', array( 'theme_advanced_buttons1' => 'bold, italic, ul, pH, pH_min', "media_buttons" => true, "textarea_rows" => 8, "tabindex" => 4 ) );
Very easy:
<?php wp_editor( $content, $editor_id ); ?>
This will generate a lot of html tags. But the one you will be interested in is the textarea with its name set to $editor_id. So when the form is submitted, you can save that content.
You can find more info here: https://codex.wordpress.org/Function_Reference/wp_editor

Creating "ON/OFF News Links" functionality for a block created with View Module

I'm a drupal newbie who needs some advice...
I have a news list block at homepage, created with View Module. It is listing all added news' title and link. Everything is cool so far. Now I need to add an ON/OFF option at admin side for homepage news block. When the setting is ON, it will work as it is. When it is OFF, only the titles will be listed with no linking to news detail page.
So, now where should I add this ON/OFF option? I have only add/edit/delete pages for each news, there is no common news page to add such option. Should I create an admin page with such ON/OFF option in? Also I think I need to create a db table to keep this ON/OFF status. and controlling this value at homepage block, if it is 1 or 0, and displaying links according to db value :/
it looks too long way
Create db table
Create an page with ON/OFF option in
add php codes to update db for admin's choice
get the db value in homepage block to display links, etc.
is there any shorter, better way to do what I need?
Appreciate helps so much!!! Thanks a lot!!
You definitely don't need to create any database tables for something like that. If you want a basic admin page, you will need to write a simple module though. First follow this quick start guide for setting up a basic module. (Note: You don't need to add those database queries in your .install file)
Once you have your module enabled...
1) In your mynewmodule.module file, add a menu entry to tell Drupal where your admin page can be accessed:
function mynewmodule_menu() {
return array(
'admin/settings/mynewmodule' => array(
'title' => 'My New Module',
'description' => 'Change settings for news display.',
'page callback' => 'drupal_get_form',
'page arguments' => array('mynewmodule_admin_form'),
'acces callback' => 'user_access',
'access arguments' => array('administer site configuration'),
),
);
}
2) Also in your mynewmodule.module file, add a function to create the form you just referenced in the menu entry:
function mynewmodule_admin_form() {
$form = array();
$form['mynewmodule-on-off-switch'] = array(
'#type' => 'checkbox',
'#title' => t('Enable news links'),
'#description' => t('Control whether news items are linked to stories'),
'#default_value' => variable_get('mynewmodule-on-off-switch', 1),
);
return system_settings_form($form);
}
3) Clear your cache to make Drupal recognize your admin page (you need to clear any time you make changes to mynewmodule_menu()). You can clear it here: admin/settings/performance
4) Visit admin/settings/mynewmodule to see your admin form. The way it works is when you save the configuration, Drupal will save a variable called "mynewmodule-on-off-switch" (same name as the array key in the form) to the variables table in the database. You can get this value anywhere by using variable_get().
create a form at admin/settings/on-off-switch.
on the form submit function, variable_set('on/off switch', $value) (try using booleans for the value).
then on the view theme, check for variable_get('on/off switch', $default_value) before printing the links.
Drupal's weakness, IMHO, is the sheer number of admin settings to configure to get a site up, and you don't want to be adding to that.
What I would do is to have the view expose two different blocks, one with the full view, one with the abbreviated view. Then all the configuration can be done through the block interface, which will be much more flexible in the long run. By, for example: using wildcards or php code for block visibility; showing different views to users with different roles; allowing visitors to control which view they see; exposing the two views to the theming engine more cleanly; and integration with any other module that works with blocks.

how to add additional message in a Drupal form

I would like to additional instructions to a custom Drupal form, similar to hook_help, but at the bottom of the form. Is there a function or hook available for this?
If you add an element to the form with no type, its' value will be displayed as HTML on the page.
See here
$form['contact_information'] = array(
'#value' => t('You can leave us a message using the contact form below.'),
);
theming forms: http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6
you can cck or other modules...

Drupal 6: CAPTCHA on a custom form

How can I add CAPTCHA (version 6.x-2.0-rc3) to custom form in Drupal 6?
Is it just me or is it really difficult to find any good documentation on Drupal....
A quick search in the CAPTCHA issues queue led me here.
The key example code seems to be:
$form['captcha'] = array(
'#type' => 'captcha',
'#captcha_type' => 'captcha/Math',
);
There is also some good information in the module readmes.
what do you mean by 'custom form' as there's many interpretations of those words ..
meanwhile did you find this
captcha/drupal video tutorial ?

Resources