Posted by nasium on April 23, 2007 at 2:18am
Is there a way that I can remove the preview button in my custom node?
When I send the user to the add screen, i use this function:
function weblinks_form_weblink_user() {
drupal_goto("node/add/weblinks", $query = "ref=user");
}
The only way I can think of is hacking the core code...
please help...
Comments
I was looking for the same thing and found..
hi nasium,
I don't know if you're still interested in this - I found your post because I was looking for the same thing and found it from here: http://drupal.org/node/62319
First I was a bit scared of going for my (first) own 'module' - but it is really not that dramatic.. For drupal 5.x you just need the .module and the .info file and throw the function (as descriped on http://drupal.org/node/62319) in that .module-file and that's basically it..
I added a form_id-check to control which form has a preview button and which form not.. - ..the 'echo' is there to find out what form_id I have on a specific page - here's my code for hiding the preview button from the comments and from mycontenttype:
function mymodulename_form_alter($form_id, &$form) {
// echo("form_id".$form_id);
if(($form_id=="mycontenttype_node_form")||($form_id=="comment_form")) {
unset ($form['preview']);
}
}
..hope it helps..
greetings, t..
___________________________
my pictures: www.bilderbook.org
___________________________
my pictures: www.bilderbook.org
Thankyou
Thankyou for leaving this how-to , it worked first time.
..thank you for the thank
..thank you for the thank you! ..glad to hear it helped..:]
greetz, t..
___________________________
my pictures: www.bilderbook.org
___________________________
my pictures: www.bilderbook.org
Can't figure it out
Hi Tille
thanks for the info on how to deal with the pesky Preview button. However, I can't get it to work - I've created a nopreview.module (with nothing but the your code) and a nopreview.info file and placed them in a "nopreview" folder with my other modules but it's not showing up in the module list? What am I doing wrong.
Thanks very much for any help and cheerio
Ole
Can't hide Preview button - module showing, but not working
Hi,
well, here's what I added for the module:
<?php
// $Id$
/**
* @file
* Hides preview button on nodes.
*/
/**
* From: http://drupal.org/node/138393#comment-259431
*
* Make sure to add the correct node-types below:
*/
function mymodulename_form_alter($form_id, &$form) {
// echo("form_id".$form_id);
if(($form_id=="contractor_node_form")||($form_id=="contractor_coupon_node_form")) {
unset ($form['preview']);
}
}
and the info file:
; $Id$name = nopreview
description = Allows users to annotate nodes.
package = Custom
version = "$Name$"
Uploaded in a folder called "nopreview" to sites/all/modules.
I enabled it on the modules page. Then tried to create those content-types - but preview button still shows.
then considered maybe it was the ccontributed theme I was using - so switched to Garland. Still didn't hide preview button.
Does anyone have any insight into this?
Thanks in advance!
Scott
Scott Rigby
http://dlc-solutions.com
http://basekamp.com
http://PlausibleArtworlds.org
rename function
I believe you are forgetting to rename the "function mymodule_form_alter(..." part. In your example, you would put "function nopreview_form_alter" instead. and this file would be named nopreview.module. The info file would then be named nopreview.info (putting both of those files in a folder called /sites/all/modules/nopreview).
about hiding the preview button
I have content type which is developed using cck.I donot want the preview button on that.Is your approach help me.
When one door closes,another opens, but if we spend too much time concentrating on the closed door we don't notice the open one.
check form names once again
un comment the echo("form_id".$form_id); and check once again whether form ids are written correct. one more thing you need to check is function name. if your module name is "noextrainfo", your function name should be noextrainfo_form_alter($form_id,&$form).
that's it.
RK
Can I do it without a module?
Hi,
Is it possible to hide the Preview button without a module? I just want to hide it for 1 content type. Thanks,
David
Using CSS
Try this using CSS
I entered the following into my themes style sheet. Worked a charm. But it does remove all preview buttons on the site.
#edit-preview {
display:none;
}
create a
create a comment-form.tlp.php in your theme directory (if you don't already have one). And add this:
<?php$form['preview'] = null;
print drupal_render($form);
?>
--
Tom
kirkdesigns.co.uk - web design and development
--
Tom
www.systemseed.com - drupal development. drupal training. drupal support.
Yes you can
I got this from another thread and I modified it slightly to work within my own module
/*** Here we disable in step 1 the submit button. In step 2 we disable the preview button*/
function metadatagath_form_alter(&$form, $form_state, $form_id){
if($form_id == 'metadatagath_node_form'){
if($form['step']['#value'] < 2){
$form['#rebuild'] = TRUE;
unset($form['buttons']['submit']);
$form['buttons']['preview']['#value'] = t('Next');
}
else{
$form['#rebuild'] = FALSE;
$form['#redirect'] = TRUE;
unset($form['buttons']['preview']);
}
}
}
This line: unset($form['buttons']['preview']);
That removes the preview button just for this "metadatagath_node_form" form.
It works!
Perfectly! Just changing the appropriated variables, it works perfectly. Thanks!
porcupinetree.com.br
module to hide preview button from settings
<?php
// $Id:
/**
* Implementation of hook_menu
*
* For settings page
*/
function nopreview_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/nopreview',
'access' => user_access('administer site configuration'),
'title' => t('Hide Preview Buttons'),
'description' => t('Hide Preview Buttons by content type.'),
'callback' => 'drupal_get_form',
'callback arguments' => array('nopreview_settings_form'),
'type' => MENU_NORMAL_ITEM,
);
}
return $items;
}
/**
* Form function for settings
*/
function nopreview_settings_form() {
$options = array('yes','no');
$node_types = node_get_types('names');
$node_previews = variable_get('nopreview_node_types', array());
$form['description'] = array(
'#tyoe' => 'markup',
'#weight' => '-100',
'#value' => t('Use these settings to configure which content types to hide the preview button for'),
);
$form['nopreview_node_types'] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Preview button by node type'),
);
foreach ($node_types as $key => $value) {
$form['nopreview_node_types'][$key] = array(
'#type' => 'select',
'#title' => t('Show Preview button for'). " $value",
'#default_value' => $node_previews[$key],
'#options' => $options,
);
}
return system_settings_form($form);
}
/**
* Hide the buttons
*/
function nopreview_form_alter($form_id, &$form) {
$nopreviews = variable_get('nopreview_node_types', array());
if ($nopreviews[$form['type']['#value']] == 1) {
unset ($form['preview']);
}
}
?>
No workie
....at least not with my D6.4 build.
warning: Missing argument 1 for nopreview_menu() in /home/my_website/public_html/sites/all/modules/nopreview/nopreview.module on line 10.
Line numbers added for clarity:
<?php10 function nopreview_menu($may_cache) {
11 $items = array();
12 if ($may_cache) {
13 $items[] = array(
14 'path' => 'admin/settings/nopreview',
15 'access' => user_access('administer site configuration'),
16 'title' => t('Hide Preview Buttons'),
17 'description' => t('Hide Preview Buttons by content type.'),
18 'callback' => 'drupal_get_form',
19 'callback arguments' => array('nopreview_settings_form'),
20 'type' => MENU_NORMAL_ITEM,
21 );
22 }
23 return $items;
24 }
?>
Anybody have any ideas...??
I've tried every trick mentioned here so far to not show a simple "preview" button (or better, disable it), with nil results....
Cheers,
//TB
http://BrewReview.info
[FIXED]! This kills Preview w/ D6.4
Came across this sandbox, where "preview_plug" module does EXACTLY what I needed: killing off the Preview button on a node-type by node-type basis (or across the entire site, by default):
http://cvs.drupal.org/viewvc.py/drupal/contributions/sandbox/deekayen/mo...
Cheers!
//TB
http://BrewReview.info
Hiding PREVIEW button for one specific page with css
Hiding PREVIEW button for one specific page with css: http://drupal.org/node/194890#comment-1161353
---
How to contribute to Drupal.
---
How to contribute to Drupal.
Drupal 6
nopreview.module
<?php
// $Id:
/**
* Implementation of hook_menu
*
* For settings page
*/
function nopreview_menu() {
$items = array();
$items['admin/settings/nopreview'] = array(
'title' => 'Hide Preview Buttons',
'description' => 'Hide Preview Buttons by content type.',
'page callback' => 'drupal_get_form',
'page arguments' => array('nopreview_settings_form'),
'access arguments' => array('administer imageapi'),
);
return $items;
}
/**
* Form function for settings
*/
function nopreview_settings_form() {
$options = array('yes','no');
$node_types = node_get_types('names');
$node_previews = variable_get('nopreview_node_types', array());
$form['description'] = array(
'#tyoe' => 'markup',
'#weight' => '-100',
'#value' => t('Use these settings to configure which content types to hide the preview button for'),
);
$form['nopreview_node_types'] = array(
'#tree' => TRUE,
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#title' => t('Preview button by node type'),
);
foreach ($node_types as $key => $value) {
$form['nopreview_node_types'][$key] = array(
'#type' => 'select',
'#title' => t('Show Preview button for'). " $value",
'#default_value' => $node_previews[$key],
'#options' => $options,
);
}
return system_settings_form($form);
}
/**
* Hide the buttons
*/
function nopreview_form_alter(&$form, $form_state, $form_id) {
$nopreviews = variable_get('nopreview_node_types', array());
if ($nopreviews[$form['type']['#value']] == 1) {
unset($form['buttons']['preview']);
}
}
?>
nopreview.info
name = No-Preview Button
description = Remove preview button (especially for courses)
package = Other
core = 6.x
version = "6.x-1.0"
core = "6.x"
project = "No-Preview Button"
That is brilliant
Thanks.
Any chance we could expand it to cover comments and their preview buttons...?
That's fantastic, but as
That's fantastic, but as another pointed out, does not account for comment forms.
In Drupal 6.10 I have tried both these and neither works:
if ($form_id == "comment_form") {unset($form['preview']);
}
if ($form_id == "comment_form") {unset($form['buttons']['preview']);
}
Anyone have any idea why neither of these works? Hmmmmmm.
D'oh!
The first one of mine should work. I'm working with another developer who has been focused on theming. He had another custom module that re-created the comment form's Preview button after I unset it (because his module is 'heavier' than mine, it executes its hooks after mine). No wonder!
Unsetting wrong var
Use:
unset($form['buttons']['preview']);Drupal 5
If you ever decide to contribute this as a module, let me know. I have ported it to drupal 5 if someone wants it.
Contributed module?
could the proposed solution(s) find its way into contributed modules?
There is now a module for that
Just for the record:
http://drupal.org/project/preview
then go to "Post Settings" and there you can globally disable the preview button.
Just give it an access = 0
guys, just give it an access = 0 to almost anything you want to hide in the form..
this is something that I've been using for a long time now and it's better than unset because sometime doing unset breaks down the form.. once I've tried to hide the path and menu items (collapsible) by unsettling them and the nodes would not appear in proper places.. but hiding is not an extreme solution as unsettling, because everything is still there, you just choose to hide it in the form that the user is previewing.
example - Hiding the preview button.
ModuleName_form_alter(&$form, &$form_state, $form_id) {
$form['preview']['#access'] = 0;
}
Remeber that that first you have to put preview settings optional.. it's not wise to hide something that is required.. you can put preview optionally by going to the content type settings (under edit)
hope this helps..
take care..
i've just realize that this
i've just realize that this is under drupal 5... this solution is for drupal 6 (also i don't know if it will work in drupal 7, although I'm guessing it will)..