Is it possible to disable & hide the preview button for all nodes?
I'm building a single user brochure site in drupal 4.6 & the preview button (and following actions) confuses my "very base level understanding" client. With lots of other form elements I've simply used .css to hide some things though the preview button doesn't have a reference...

Ta for any help :)

Comments

merlinofchaos’s picture

The only way you're going to manage to do that in 4.6 is to actually hack node.module and remove the preview button. You may need to do the same in comment module, and anywhere else you find preview to be an issue.

in 4.7 you could probably theme the node form and hide the rendering of the button, but that isn't possible in 4.6.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

tomski777’s picture

Cheers fro ya input Merlin.
I was hoping to avoid a hack of node.module - oh well!

><>tomskii
><>www.mutinyarts.co.uk

jmanico’s picture

For 4.7, I just did this in my form theme function and it worked. Bye bye preview!

$output .= "<!-- ";
$output .= form_render($form['preview']);
$output .= "--!>";
tomski777’s picture

Thanks jmanico - At last the holy grail!!! :)

Will undo some nasty hacks on old sites...

tom

><>tomskii
><>www.theanthillsocial.co.uk

ypeng33’s picture

I am using drupal5.

add the following code to template.php
function phptemplate_node_form($form) { //only for CCK form, invalid for account
//print path_to_theme().'/'.$form['type']['#value'].'_form.tpl.php'; die;
if(file_exists(path_to_theme().'/'.$form['type']['#value'].'_form.tpl.php')) {
return _phptemplate_callback($form['type']['#value'].'_form', array('user' => $user, 'form' => $form));
}
}

Say the content type of your CCK form is test.
in test_form.tpl.php
add
$form['preview']="" ;
print drupal_render($form);

Hope it helps.

blueflowers’s picture

In the case of form_alter (D5) simply do this:


mymodule_form_alter($form_id, &$form){

$form['preview']= NULL;

}

untested for D6

Fourth Wall Media
Toronto, Canada

kevinhammer’s picture

Here's a dirty hack to hide the preview button for all content types in Drupal 6. Comment this block of code out in your modules/node/node.pages.inc file:

  /*$form['buttons']['preview'] = array(
    '#type' => 'submit',
    '#value' => t('Preview'),
    '#weight' => 10,
    '#submit' => array('node_form_build_preview'),
  );*/

There must be a slick way to simply remove this ['preview'] element from the $form['buttons'] array using a module. It would be nice to not hack the core like this :) But my client isn't paying for slick, just DONE!

kevinhammer’s picture

Ok, I felt bad and learned how to make this into a nice module. It adds a check box in each content type form in the Workflow section to hide preview for node editing forms of this content type.

hide_preview.info

name = Hide Preview
description = Hides the preview button for all content type editing forms.
package = Other
core = 6.x

hide_preview.module

function hide_preview_form_node_type_form_alter(&$form, $form_state) {
  $form['workflow']['hide_preview'] = array(
    '#type' => 'checkbox',
    '#title' => t('Hide Preview Button'),
    '#default_value' => variable_get('hide_preview_'. $form['#node_type']->type, 0),
    '#description' => t('Check this box to Hide the Preview button for this node type.')
  );
}
function hide_preview_form_alter(&$form, $form_state, $form_id) {
  if (isset($form['type']['#value']) && ($form_id == $form['type']['#value'] .'_node_form')) {

    // check if this content_type has the hide_preview function enabled and make sure it's a node edit or add form
    if ( (variable_get('hide_preview_'. $form['type']['#value'], 0) == 1) &&
          ( (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == 'edit') || (arg(0) == 'node' && arg(1) == 'add') )
        ) {
      unset($form['buttons']['preview']);
    }
  }

}
davidmolliere’s picture

Hey thanks for this little module, which I came accross after quite a bit of searching and by pure chance... could this be added to modules ?

It may be a small module but definitely a needed one !
Again, thanks :D

Edit : Just have a little problem to install this, I saved both files above upoladed to a newly hide_preview folder in modules/ and went to admin/build/modules but Hide Preview doesn't appear.

I thought it was because of the closing ?> (which I removed, it seems .module files don't have closing ?> but changed nothing).

Where did I go wrong ?

IWasBornToWin’s picture

This module worked fine for me. Although, when I first saved the .info and .module files above, I noticed they were actually saved as .info.txt and .module.txt. I'm not sure if that's your poblem or not? I had to remove the .txt part from the file name.

Besides that, I copied and pasted the code into a blank notepad file, saved each as hide_preview.info and hide_preview.module. Then created a folder in modules called hide_preview. Copied both files into that folder. Went to modules and enabled the Hide Preview module. Didn't see any permissions that needed to be enabled and it worked properly.

Unfortunately, after doing all of this, I learned this wasn't what I was really looking for. I was wanting to disbale the preview button for comments, not for editing nodes.

NULL-2’s picture

worked fine....thaaaaanks man :))))))))))

albertski’s picture

Thanks for sharing kevinhammer!

aibrahimov’s picture

It worked like a charm! Why did not you publish it as a module?

webthingee’s picture

function nameofyourmoudle_form_alter(&$form, &$form_state, $form_id) {
	$form['buttons']['preview'] = NULL;
}
jerome72’s picture

Thank you for the tip webthingee!

I used it for my custom node only :

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  if (arg(2) == 'mymodule') $form['buttons']['preview'] = NULL;
}
cmav77’s picture

For a detailed explanation of how to solve this cleanly in Drupal 6, check out How to remove or hide the 'Preview' button in Drupal 6. Suggestions similar to above (using hook_form_alter), but also using the unset() function as well as how to target specific node types based on form IDs. Hope that helps the next person that comes across this page!

rootdownmedia’s picture

I was trying to remove the Preview button on all Comment forms but none of the suggested .module files above worked.

Heres one that did (note: you need to add your custom module name to the beginning of the form_alter function):

<?php
function CUSTOMMODULENAME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'comment_form') {
    unset($form['preview']);
  }
}
?>
gmaximus’s picture

Thanks for the pointer in the right direction... Maybe you were using a different version of Drupal... I had to alter your line from:

unset($form['preview']);

to

unset($form['buttons']['preview']);

I'm also using it for the node form not comments

I've often called Google "gods homepage", now I call chatgpt "conversations with God."

I am always interested in paid work... Contact me through Online Business Builders

not_Dries_Buytaert’s picture

The "Content Form Jammer" submodule (http://drupal.org/project/jammer) allows removing the preview button per content type.

Bill Choy’s picture

function mymodule_form_alter(&$form, ...) {
// disable preview for D7
if ($form['#node_edit_form']) {
unset($form['actions']['preview']);
}
}

Hiking up the Drupal learning developer curve