Hi,

Is there a way to totally turn off the preview option from comments? At the moment it is on optional, but I would like to remove the button totally.

Thanks,
hf

Comments

wellsy’s picture

admin/comment/configure

and set your preference
Preview comment:
Optional
Required

EDIT: Ooops....I really should read the question better>disregard the answer.

wellsy

orchidsonline.com.au

cel4145’s picture

Once you have made it optional, it seems like there ought to be a way to use the "display: none" line in your theme style sheet to make the button disappear.

cmsproducer’s picture

If you are upto editing PHP, go to the modules directory and find the comment.module, edit the line 1419 and disable the creation of the preview button. Remember that anything you tweak in the modules' code will be erased whenever you upgrade your Drupal installation and replace that file with an updated one... Keep a record of your changes so that you can implement them again once you upgrade (in future).

You can customise the look and features of your comment view by editing the comment specific template found in your Theme's folder (it's called comment.tpl.php).

Curious: On a different note, it does nto harm you to have the preview button as an option, why go through all this to remove a edit level option?
-----
iDonny - Web CMS Development, Design, and Web Marketing Advice

hf’s picture

iDonny,

Great job, thanks a lot!

I have tried iDonny's way (modifying comment.module), and it worked perfectly. I did not have to change the theme template (I am using the "pushbutton" template).

For your question: I have examined statistics, and I noticed, that lot of visitors go into the comments, but do not send in any comment. Since my page is quite simple, and I have just a few comments, I thought I make it simple and obvious: just push the button and the comment is done, users cannot go wrong. Whoever is registered still can change the comment anyway.

Thanks for everybody who answered!

hf

mr.j’s picture

Create a file called comment-form.tpl.php in your theme directory and put the following in it:

<?php 
	$form['preview'] = null;
	print drupal_render($form);
?>
Paintbox’s picture

For the record and clarity sake for people visiting this by search (as I just did) to make the above work,

Also add this to your template.php :

function phptemplate_comment_form($form) {
   return _phptemplate_callback('comment-form', array('form' => $form));
}

Tested for 5.x

xapadoo’s picture

Ops, sorry: This applies for drupal 5 not 4


  function yourthemename_comment_form($form) {
    unset($form['preview']);
    return drupal_render($form);
  }

Copy / paste this into your template.php and replace "yourthemename" with your theme name :)

Make sure you don't copy paste the tags

dr00b’s picture

This threw an error for me, it looks liked it balked at the "-" in my theme's filename. Perhaps dashes in theme names are not allowed? Never ran into trouble with it before though...

For now, I just added this to my stylesheet, which of course simply makes the button disappear from view:
#edit-preview
{
display: none;
}

~drOOb

ron_s’s picture

For now, I just added this to my stylesheet, which of course simply makes the button disappear from view:
#edit-preview
{
display: none;
}

The better approach is to remove the button completely using Drupal theming or by modifying the comment.tpl.php file. "display:none" is not effective and I wouldn't recommend it. Anyone using something as simple as Firebug would be able to remove the styling and click the button.

SomeGirl’s picture

Been playing around with this all night....
I got rid of line 1392 in comment.module...the line that reads something like....

$form['preview'] = array('#type' => 'button' , 'value' => t('Preview'), '#weight' => 20);
Anonymous’s picture

For Drupal 6, this provides the 'Save' button instead of just 'Preview', i.e for guests attempting to leave comments (really annoying if you have captcha enabled, otherwise they have to enter the captcha for both the preview and the save after that):

comment.module

/**
 * Comment preview is optional.
 */
define('COMMENT_PREVIEW_OPTIONAL', 0);

/**
 * Comment preview is required.
 */
define('COMMENT_PREVIEW_REQUIRED', 0);
emancipator’s picture

Is there not a setting in the admin page? or do we have to modify the code?

Anonymous’s picture

It looks like comment preferences are edited on a per-content-type basis in Drupal 6.x. For example, if you want to change the settings for comments on blogs, navigate to Administer -> Content Types. On the "Blog Entry" row, click "edit" and scroll down to select "Comment Settings". There you can set preview to optional. It still won't fix having to enter a CAPTCHA for both preview and save, but at least a user can skip the preview.

FYI: This info is derived from a reply by simon_ives on http://drupal.org/node/23703 (dated February 28, 2008 - 23:41). I've tried it and it seems to be a reasonable compromise between forcing users to enter two CAPTCHAs and manually updating comment.module.

agonostic’s picture

Modify line 1389 in the file comment.module:

if (!form_get_errors() && ((variable_get('comment_preview_'. $node->type, COMMENT_PREVIEW_REQUIRED) == COMMENT_PREVIEW_OPTIONAL) || ($op == t('Preview')) || ($op == t('Save')))) {

To:

if (!form_get_errors()) {

and comment the line 1393

//$form['preview'] = array('#type' => 'button', '#value' => t('Preview'), '#weight' => 20);
rootdownmedia’s picture

Is there a way to use this method in template.php so you dont need to hack the core commenting module?

Unity’s picture

SomeGirl's method worked perfectly. I'm using Drupal 5, and the line was nearly identical. The line number was different, but I just did a text search to find it. After commenting out this line, everything works perfectly and the "Preview comment" button is gone.

I simply commented out this line in comment.module:

$form['preview'] = array('#type' => 'button', '#value' => t('Preview comment'), '#weight' => 19);
aterchin’s picture

please don't hack the core modules. if you're trying the tip from comment http://drupal.org/node/57842#comment-815045, and having problems with your theme name use 'phptemplate' instead of your theme name in template.php like

function phptemplate_comment_form($form) {
	unset($form['preview']);
		return drupal_render($form);
}
Anonymous’s picture

I tried the above and it didn't work, so then I re-read this thread and noticed the comment from dbc60 http://drupal.org/node/57842#comment-998037

So much easier to just edit comment settings at admin/content/node-type/forum.

Just wanted to bring attention to this in case someone glossed over it like I did...

stevekerouac’s picture

A few people here are getting confused about what the post is trying to achieve, eg: to TURN OFF preview altogether, not just make it optional. You cannot achieve this with admin settings.

The phptemplate code above does not work for V6 - any ideas ?

netsensei’s picture

You need to create your own little module that implements the hook_form_alter function. This allows you to change the form and all it's elements without hacking core.

This is the code that goes into your MODULE_NAME.module file:

/**
 * Implementation of hook_form_alter
 **/
function MODULE_NAME_form_alter(&$form, $form_state, $form_id) {
  if ($form_id = 'comment_form') {
    unset($form['preview']);
  }
}

It basically removes the button from the form array before the form is rendered. You could also use this to modify other elements of the comment form.

marcushenningsen’s picture

Thanks for the snippet. I put into a module and placed it with the jammer module, and it works fine.

Here is a link to the relevant issue for the jammer module: http://drupal.org/node/517240#comment-1889094

mistergroove’s picture

Further to netsensei's comment, you can also you the hook_form_FORM_ID_alter in your module if you prefer :

/**
* Implementation of hook_form_FORM_ID_alter
**/
function MODULENAME_form_comment_form_alter(&$form, $form_state)   {
  unset($form['preview']);
}

Which goes into your MODULENAME.module file.

http://www.atomicant.co.uk

W.M.’s picture

I have tested this code. It works perfectly. Thanks!

ali.sharif’s picture

Hi
You must go to in content type of your section and edit the configuration in address :admin/content/types
for example : if you want to turn off preview for forums you can go to management -> content type -> forum -> edit and turn off the preview comment from comment settings
also for other sections you can do this as well to turning off the preview ...

jimthunderbird’s picture

I agree with drupalcms.ir.

We should look for the settings options provided by each module as much as possible before doing custom code hacking.

Anonymous’s picture

Under content type/edit you can only set preview comment to optional or required - you can't turn it off all together

massimiliano.dongiovanni’s picture

It's not a real solution.

Add these lines in your theme's stylesheet.

#edit-preview{
display: none;
}

EDIT....
!!!Sorry I hadn't seen previous comment !!!
This trick has been suggested before.

Summit’s picture

Subscribing..still no setting to remove preview in comment.module itself?
I prefer not to change theme or modules because of not able to do a clean update then..
greetings, Martijn

zhuss’s picture

Please click http://localhost/sample/?q=admin/content/node-settings

or access Administer-->ContentManagement-->PostSettings.
Hope you can disable preview.

momper’s picture

in template.php


/**
 * MODULE COMMENT: hide preview button ->www.drupal.org/node/57842
 */

function comment_form_comment_form_alter(&$form, $form_state) {
  unset($form['preview']);
}

this works ...

wwwoliondorcom’s picture

Hi,

I don't want to hack because i will forget it during updates, so do you know if there is now a module that removes the preview button for comments ?

Thanks.

Bertjuh’s picture

Try out the Jammer module: http://drupal.org/project/jammer

wwwoliondorcom’s picture

Hi,

In case someone is still looking for this, I just disabled comment preview for Drupal 5 by doing what has been written by 2 nice guys on this page:

On Drupal 5.x
Posted by mr.j on January 18, 2008 at 6:40am

Create a file called comment-form.tpl.php in your theme directory and put the following in it:

    $form['preview'] = null;
    print drupal_render($form);

* reply

For the record and clarity
Posted by Paintbox on February 18, 2008 at 9:57am

For the record and clarity sake for people visiting this by search (as I just did) to make the above work,

Also add this to your template.php :

function phptemplate_comment_form($form) {
return _phptemplate_callback('comment-form', array('form' => $form));
}

Tested for 5.x

And it works (perfect for me as i am sure that i won't update the template).

For Drupal 6 the easiest solution is to use JAMMER module, but it seems that Jammer doesn't allow to disable PREVIEW for comments on Drupal 5, why ?!

Thanks.

shirishv’s picture

By default, Drupal is configured to force anonymous users to preview their comments before posting them. To enable users to post without previewing their comment, you might think you'd access:

Administer > Content Management > Content Settings > Post Settings

or

Administer > Comments > Configure

But it doesn't work this way

In Drupal 6, the comment preview settings are tied to each content type. Visit:

Administer > Content Management > Content Types

Refer to this url http://www.99tutes.com/content/drupal-disable-required-comment-preview.html for more details

OmarQot’s picture

comment by mistake

gdkt11’s picture

In Drupal 7, go to content type with the comments enabled. Look under Comment Settings.

yared411’s picture

Note that the form has to actions (preview and submit)

To turn off the preview button

$form['actions']['preview']['#access'] = FALSE;

To turn on the Save button in order to by pass the Perview button

$form['actions']['submit']['#access'] = TRUE;
$form['actions']['preview']['#access'] = FALSE;

That should take care of it. Also, I have seen some posting asking how to change the submit button name and I think here is how you can change the name of the submit button

$form['actions']['submit']['#value'] = "Post Comment";

All these has to be done in your custom comment.module so you will not be affected by Drupal update.

flefle’s picture

Path: /admin/structure/types/manage/[content type] -> comment settings -> Preview comment -> disabled -> save content type setting.

Regs,
Francis

martindespaux’s picture

Here i post the solution for me:

hook_form_comment_form_alter(&$form, $form_state) {
unset($form['actions']['preview']);
}

wturrell’s picture

(as this remains the top Google result for disable/turn off comment preview)

You can do it through the UI on a field-by-field basis - specifically you:

- Edit the content type the comment is attached to (NOT the comment type)
- Go to the Manage Fields tab, then edit the comment field
- Scroll down the bottom of the Edit tab for the 'Preview comment' options - there are radio buttons for Disabled, Optional and Required.

Nikita Petrov’s picture

Thank you! A perfect solution in a weird drupal thread, but you are right, Google rated it as the best relevant page even when 8 is an actual version.